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 によってスレッドが実際に終了することはありません。 これらのメソッドは、Application オブジェクトがリッスンするThreadExit イベントを発生させます。 その後、 Application オブジェクトはスレッドを終了します。

適用対象