다음을 통해 공유


Application.Exit 메서드

정의

모든 메시지 펌프는 종료해야 하며 메시지가 처리된 후 모든 애플리케이션 창을 닫습니다.

오버로드

Name Description
Exit()

모든 메시지 펌프는 종료해야 하며 메시지가 처리된 후 모든 애플리케이션 창을 닫습니다.

Exit(CancelEventArgs)

모든 메시지 펌프는 종료해야 하며 메시지가 처리된 후 모든 애플리케이션 창을 닫습니다.

Exit()

Source:
Application.cs
Source:
Application.cs
Source:
Application.cs
Source:
Application.cs
Source:
Application.cs

모든 메시지 펌프는 종료해야 하며 메시지가 처리된 후 모든 애플리케이션 창을 닫습니다.

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

예제

다음 코드 예제에서는 폼의 목록 상자에 숫자를 나열합니다. 클릭 button1할 때마다 애플리케이션은 목록에 다른 번호를 추가합니다.

메서드 RunMainlistBox1button1을 만드는 애플리케이션을 시작하고 . 사용자가 클릭하면 button1메서드는 button1_Click 목록 상자에 1~3개의 숫자를 추가하고 을 표시합니다 MessageBox. 사용자가 [아니요 ]를 MessageBox클릭하면 메서드가 button1_Click 목록에 다른 숫자를 추가합니다. 사용자가 [예]를 클릭하면 애플리케이션이 호출 Exit하여 큐에 남아 있는 모든 메시지를 처리한 다음 종료합니다.

이 예제에서는 이를 listBox1 요구하며 button1 인스턴스화되어 폼에 배치되었습니다.

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

설명

메서드는 Exit 모든 스레드에서 실행 중인 모든 메시지 루프를 중지하고 애플리케이션의 모든 창을 닫습니다. 이 메서드가 반드시 애플리케이션을 종료하도록 강제하는 것은 아닙니다. Exit 이 메서드는 일반적으로 메시지 루프 내에서 호출되고 강제로 Run 반환됩니다. 현재 스레드에 대해서만 메시지 루프를 종료하려면 .를 호출합니다 ExitThread.

Exit 는 다음 이벤트를 발생시키고 연결된 조건부 작업을 수행합니다.

  • FormClosing 속성이 나타내는 모든 폼에 대해 이벤트가 발생합니다OpenForms. 이 이벤트는 해당 매개 변수의 FormClosingEventArgs 속성을 .로 설정 Cancel 하여 취소할 true수 있습니다.

  • 처리기 중 하나 이상이 이벤트를 Exit 취소하면 추가 작업 없이 반환됩니다. 그렇지 않으면 열려 있는 FormClosed 모든 폼에 대해 이벤트가 발생한 다음 실행 중인 모든 메시지 루프 및 양식이 닫힙니다.

메모

메서드는 Exit 사용되지 않는 이벤트 및 Closing 이벤트를 발생 Closed 시키지 않습니다.

추가 정보

적용 대상

Exit(CancelEventArgs)

Source:
Application.cs
Source:
Application.cs
Source:
Application.cs
Source:
Application.cs
Source:
Application.cs

모든 메시지 펌프는 종료해야 하며 메시지가 처리된 후 모든 애플리케이션 창을 닫습니다.

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)

매개 변수

e
CancelEventArgs

애플리케이션 내에서 종료를 취소했는지 여부를 Form 반환합니다.

추가 정보

적용 대상