ApplicationContext.ExitThread Yöntem

Tanım

İş parçacığının ileti döngüsünü sonlandırır.

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

Örnekler

Aşağıdaki kod örneği, sınıfa genel bakış bölümündeki örnekten ApplicationContext bir alıntıdır. Bu örnek açık formları izler ve tüm formlar kapatıldığında geçerli iş parçacığından çıkar. OnFormClosed yöntemi, olay için bir olay işleyicidirClosed. Açık form sayısı 0'a eşit olduğunda, geçerli iş parçacığından yöntemi çağrılarak ExitThread çıkılır. Form sayısı, form gösterildiğinde formCount değişken artırılarak ve form kapatıldığında azalarak izlenir.

Bazı kodlar kısalık amacıyla gösterilmez. Kod listesinin tamamı için bkz 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

Açıklamalar

Bu yöntem çağrısında bulunur ExitThreadCore.

Not

ExitThread ve ExitThreadCore aslında iş parçacığının sonlandırılmalarına neden olmaz. Bu yöntemler, nesnenin ThreadExitApplication dinlediği olayı tetikler. Nesne Application daha sonra iş parçacığını sonlandırır.

Şunlara uygulanır