ApplicationContext.ExitThread Metode
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mengakhiri perulangan pesan utas.
public:
void ExitThread();
public void ExitThread();
member this.ExitThread : unit -> unit
Public Sub ExitThread ()
Contoh
Contoh kode berikut adalah kutipan dari contoh dalam ApplicationContext gambaran umum kelas. Contoh ini melacak formulir terbuka dan keluar dari utas saat ini ketika semua formulir ditutup. Metode OnFormClosed ini adalah penanganan aktivitas untuk peristiwa tersebut Closed . Ketika jumlah formulir terbuka sama dengan 0, maka utas saat ini keluar dengan memanggil ExitThread metode . Jumlah formulir dilacak dengan menaikkan formCount variabel ketika formulir ditampilkan, dan menguranginya saat formulir ditutup.
Beberapa kode tidak ditampilkan untuk tujuan brevity. Lihat ApplicationContext untuk seluruh daftar kode.
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
Keterangan
Metode ini memanggil ExitThreadCore.
Note
ExitThread dan ExitThreadCore janganlah kamu membuat utas terhenti. Metode ini meningkatkan ThreadExit peristiwa yang didengarkan Application objek. Objek Application kemudian mengakhiri utas.