Application.Exit Yöntem

Tanım

Tüm ileti pompalarına sonlandırmaları gerektiğini bildirir ve ardından iletiler işlendikten sonra tüm uygulama pencerelerini kapatır.

Aşırı Yüklemeler

Exit()

Tüm ileti pompalarına sonlandırmaları gerektiğini bildirir ve ardından iletiler işlendikten sonra tüm uygulama pencerelerini kapatır.

Exit(CancelEventArgs)

Tüm ileti pompalarına sonlandırmaları gerektiğini bildirir ve ardından iletiler işlendikten sonra tüm uygulama pencerelerini kapatır.

Exit()

Tüm ileti pompalarına sonlandırmaları gerektiğini bildirir ve ardından iletiler işlendikten sonra tüm uygulama pencerelerini kapatır.

public:
 static void Exit();
public static void Exit ();
static member Exit : unit -> unit
Public Shared Sub Exit ()

Örnekler

Aşağıdaki kod örneği, formdaki liste kutusundaki sayıları listeler. öğesine her tıkladığınızda button1, uygulama listeye başka bir sayı ekler.

Main yöntemi, ve formlarını listBox1button1oluşturan uygulamayı başlatmak için öğesini çağırırRun. Kullanıcı öğesine button1_Click tıkladığındabutton1, yöntem liste kutusuna bire üç sayı ekler ve bir MessageBoxgörüntüler. Kullanıcı üzerinde MessageBoxHayır'abutton1_Click tıklarsa yöntemi listeye başka bir sayı ekler. Kullanıcı Evet'e tıklarsa, uygulama kuyruktaki kalan tüm iletileri işlemek ve ardından çıkmak için öğesini çağırır Exit.

Örnek, örneğin oluşturulmasını ve button1 forma yerleştirilmesini gerektirirlistBox1.

public:
   static void main()
   {
      // Starts the application.
      Application::Run( gcnew Form1 );
   }

private:
   void button1_Click( Object^ sender, System::EventArgs^ e )
   {
      // Populates a list box with three numbers.
      int i = 3;
      for ( int j = 1; j <= i; j++ )
      {
         listBox1->Items->Add( j );
      }
      
      /* Determines whether the user wants to exit the application.
       * If not, adds another number to the list box. */
      while ( MessageBox::Show( "Exit application?", "",
         MessageBoxButtons::YesNo ) == ::DialogResult::No )
      {
         // Increments the counter ands add the number to the list box.
         i++;
         listBox1->Items->Add( i );
      }
      
      // The user wants to exit the application. Close everything down.
      Application::Exit();
   }
public static void Main(string[] args) {
    // Starts the application.
    Application.Run(new Form1());
 }

 private void button1_Click(object sender, System.EventArgs e) {
    // Populates a list box with three numbers.
    int i = 3;
    for(int j=1; j<=i; j++) {
       listBox1.Items.Add(j);
    }

    /* Determines whether the user wants to exit the application.
     * If not, adds another number to the list box. */
    while (MessageBox.Show("Exit application?", "", MessageBoxButtons.YesNo) ==
       DialogResult.No) {
       // Increments the counter ands add the number to the list box.
       i++;
       listBox1.Items.Add(i);
    }

    // The user wants to exit the application. Close everything down.
    Application.Exit();
 }
<STAThread()> _
Shared Sub Main() 	
   ' Starts the application.
   Application.Run(New Form1())
End Sub

Private Sub button1_Click(sender As object, e As System.EventArgs)
   ' Populates a list box with three numbers.
   Dim i As Integer = 3
   Dim j As Integer
   For j = 1 To i - 1
      listBox1.Items.Add(j)
   Next

   ' Checks to see whether the user wants to exit the application.
   ' If not, adds another number to the list box.
   While (MessageBox.Show("Exit application?", "", MessageBoxButtons.YesNo) = _ 
      DialogResult.No)
      ' Increments the counter and adds the number to the list box.
      i = i + 1
      listBox1.Items.Add(i)
   End While

   ' The user wants to exit the application. Close everything down.
   Application.Exit()
End Sub

Açıklamalar

Exit yöntemi, tüm iş parçacıklarında çalışan tüm ileti döngülerini durdurur ve uygulamanın tüm pencerelerini kapatır. Bu yöntem mutlaka uygulamayı çıkmaya zorlamaz. Exit yöntemi genellikle bir ileti döngüsü içinden çağrılır ve döndürülmeye zorlanırRun. Yalnızca geçerli iş parçacığı için bir ileti döngüsünden çıkmak için çağrısı yapın ExitThread.

Exit aşağıdaki olayları tetikler ve ilişkili koşullu eylemleri gerçekleştirir:

  • FormClosing özelliğiyle OpenForms temsil edilen her form için bir olay oluşturulur. Bu olay, parametresinin CancelFormClosingEventArgstrueözelliği olarak ayarlanarak iptal edilebilir.

  • İşleyicilerden biri daha olayı iptal ederse, Exit başka bir işlem yapmadan döndürür. Aksi takdirde, her açık form için bir FormClosed olay oluşturulur, ardından çalışan tüm ileti döngüleri ve formlar kapatılır.

Not

Exit yöntemi, .NET Framework 2.0 itibariyle eski olan ve Closing olaylarını tetiklemiyorClosed.

Ayrıca bkz.

Şunlara uygulanır

Exit(CancelEventArgs)

Tüm ileti pompalarına sonlandırmaları gerektiğini bildirir ve ardından iletiler işlendikten sonra tüm uygulama pencerelerini kapatır.

public:
 static void Exit(System::ComponentModel::CancelEventArgs ^ e);
public static void Exit (System.ComponentModel.CancelEventArgs e);
public static void Exit (System.ComponentModel.CancelEventArgs? e);
static member Exit : System.ComponentModel.CancelEventArgs -> unit
Public Shared Sub Exit (e As CancelEventArgs)

Parametreler

e
CancelEventArgs

Uygulama içindeki herhangi bir Form uygulamanın çıkışı iptal edip etmediğini döndürür.

Ayrıca bkz.

Şunlara uygulanır