ApplicationContext.ExitThread 메서드

정의

스레드의 메시지 루프를 종료합니다.

public:
 void ExitThread();
public void ExitThread ();
member this.ExitThread : unit -> unit
Public Sub ExitThread ()

예제

다음 코드 예제는 클래스 개요의 예제에서 발췌한 ApplicationContext 것입니다. 다음은 열려 있는 폼을 추적하고 모든 폼이 닫혀 있을 때 현재 스레드를 종료하는 예제입니다. 메서드는 OnFormClosed 이벤트에 대한 이벤트 처리기입니다 Closed . 열려 있는 양식의 수가 0과 같으면 메서드를 호출하여 현재 스레드가 ExitThread 종료됩니다. 폼의 수는 폼이 표시될 때 변수를 증가시키고 formCount 폼이 닫혀 있을 때 감소시켜 추적됩니다.

간 결함을 위해 일부 코드가 표시 되지 않습니다. 참조 ApplicationContext 전체 코드 샘플에 대 한 합니다.

void OnFormClosed( Object^ /*sender*/, EventArgs^ /*e*/ )
{
   
   // When a form is closed, decrement the count of open forms.
   // When the count gets to 0, exit the app by calling
   // ExitThread().
   _formCount--;
   if ( _formCount == 0 )
   {
      ExitThread();
   }
}
private void OnFormClosed(object sender, EventArgs e)
{
    // When a form is closed, decrement the count of open forms.

    // When the count gets to 0, exit the app by calling
    // ExitThread().
    _formCount--;
    if (_formCount == 0)
    {
        ExitThread();
    }
}
Private Sub OnFormClosed(ByVal sender As Object, ByVal e As EventArgs)
    ' When a form is closed, decrement the count of open forms.

    ' When the count gets to 0, exit the app by calling
    ' ExitThread().
    _formCount = _formCount - 1
    If (_formCount = 0) Then
        ExitThread()
    End If
End Sub

설명

이 메서드는 ExitThreadCore를 호출합니다.

참고

ExitThread 실제로 ExitThreadCore 스레드가 종료되지 않습니다. 이러한 메서드는 개체가 ThreadExit 수신 대기하는 Application 이벤트를 발생합니다. 그런 다음 개체는 Application 스레드를 종료합니다.

적용 대상