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 を呼び出します。

Note

ExitThreadExitThreadCore は、実際にはスレッドを終了させません。 これらのメソッドは、オブジェクトが ThreadExit リッスンするイベントを Application 発生させます。 その後、 オブジェクトは Application スレッドを終了します。

適用対象