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ış içindeki ö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, yöntemi çağrılarak geçerli iş parçacığından ExitThread çıkılır. Form sayısı, form gösterildiğinde değişkeni artırarak formCount 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ır ExitThreadCore.

Note

ExitThread ve ExitThreadCore iş parçacığının sonlandırılmalarına neden olmaz. Bu yöntemler, nesnesinin ThreadExit dinlediği Application olayı oluşturur. Nesne Application daha sonra iş parçacığını sonlandırır.

Şunlara uygulanır