ApplicationContext.ExitThread Metodo

Definizione

Termina il ciclo di messaggi del thread.

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

Esempio

L'esempio di codice seguente è un estratto dell'esempio nella panoramica della ApplicationContext classe . Questo esempio tiene traccia dei moduli aperti e chiude il thread corrente quando tutti i moduli vengono chiusi. Il OnFormClosed metodo è un gestore eventi per l'evento Closed . Quando il numero di moduli aperti è uguale a 0, il thread corrente viene chiuso chiamando il ExitThread metodo . Il numero di moduli viene rilevato incrementando la formCount variabile quando viene visualizzata una maschera e decrementandola quando viene chiusa una maschera.

Alcuni codici non vengono visualizzati allo scopo di brevità. Vedere ApplicationContext per l'intero elenco di codice.

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

Commenti

Questo metodo chiama ExitThreadCore.

Nota

ExitThread e ExitThreadCore non causano effettivamente l'interruzione del thread. Questi metodi generano l'evento ThreadExit in cui l'oggetto Application è in ascolto. L'oggetto Application termina quindi il thread.

Si applica a