다음을 통해 공유


방법: Window Forms 응용 프로그램의 일괄 처리 모드 사용(Visual Basic)

이 예제에서는 My.Application.Startup 이벤트를 사용하여 응용 프로그램이 문자열 /batch를 인수로 사용해 시작되었는지 확인합니다.

Window Forms 응용 프로그램에 대해 일괄 처리 모드를 활성화하려면

  1. 솔루션 탐색기에서 프로젝트를 선택합니다. 프로젝트 메뉴에서 속성을 선택합니다.

  2. 응용 프로그램 탭에서 응용 프로그램 이벤트 보기를 클릭하여 코드 편집기를 엽니다.

  3. Startup 이벤트를 처리하는 메서드를 만듭니다. 자세한 내용은 방법: 응용 프로그램 이벤트 처리(Visual Basic)를 참조하십시오.

    Private Sub MyApplication_Startup( 
        ByVal sender As Object, 
        ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs 
    ) Handles Me.Startup
    
    End Sub
    
  4. 응용 프로그램의 명령줄 인수를 반복하면서 인수 중 하나가 /batch인 경우 e 개체의 Cancel 속성을 True로 설정합니다.

    Cancel 속성이 True로 설정되어 있으면 시작 폼이 시작되지 않습니다.

    For Each s As String In My.Application.CommandLineArgs
        If s.ToLower = "/batch" Then
            ' Stop the start form from loading.
            e.Cancel = True
        End If
    Next
    
  5. e 개체의 Cancel 속성이 True로 설정되어 있으면 창 없는 작업의 기본 루틴을 호출합니다.

    If e.Cancel Then
        ' Call the main routine for windowless operation.
        Dim c As New BatchApplication
        c.Main()
    End If
    

예제

Private Sub MyApplication_Startup( 
    ByVal sender As Object, 
    ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs 
) Handles Me.Startup
    For Each s As String In My.Application.CommandLineArgs
        If s.ToLower = "/batch" Then
            ' Stop the start form from loading.
            e.Cancel = True
        End If
    Next
    If e.Cancel Then
        ' Call the main routine for windowless operation.
        Dim c As New BatchApplication
        c.Main()
    End If
End Sub
Class BatchApplication
    Sub Main()
        ' Insert code to run without a graphical user interface.
    End Sub
End Class

참고 항목

작업

방법: 명령줄 인수 액세스(Visual Basic)

참조

ApplicationBase

CommandLineArgs

개념

Visual Basic 응용 프로그램 모델 개요