ApplicationContext.ExitThread Metoda

Definicja

Przerywa pętlę komunikatu wątku.

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

Przykłady

Poniższy przykład kodu to fragment przykładu ApplicationContext w przeglądu klasy. Ten przykład śledzi otwarte formularze i zamyka bieżący wątek po zamknięciu wszystkich formularzy. Metoda OnFormClosed jest procedurą obsługi zdarzeń dla Closed zdarzenia. Gdy liczba otwartych formularzy jest równa 0, bieżący wątek jest zamykany przez wywołanie ExitThread metody . Liczba formularzy jest śledzona przez zwiększanie formCount zmiennej po wyświetleniu formularza i jej dekrementację po zamknięciu formularza.

Niektóre kody nie są wyświetlane w celu zwięzłości. Zobacz, aby zapoznać się ApplicationContext z całą listą kodu.

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

Uwagi

Ta metoda wywołuje metodę ExitThreadCore.

Note

ExitThread i ExitThreadCore w rzeczywistości nie powodują zakończenia wątku. Metody te zgłaszają ThreadExit zdarzenie, na które Application obiekt nasłuchuje. Następnie Application obiekt kończy wątek.

Dotyczy