Application.Exit 메서드

정의

모든 메시지 펌프에 끝나야 함을 알리고 메시지가 처리된 후 모든 애플리케이션 창을 닫습니다.

오버로드

Exit()

모든 메시지 펌프에 끝나야 함을 알리고 메시지가 처리된 후 모든 애플리케이션 창을 닫습니다.

Exit(CancelEventArgs)

모든 메시지 펌프에 끝나야 함을 알리고 메시지가 처리된 후 모든 애플리케이션 창을 닫습니다.

Exit()

모든 메시지 펌프에 끝나야 함을 알리고 메시지가 처리된 후 모든 애플리케이션 창을 닫습니다.

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

예제

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

합니다 Main 메서드 호출 Run 폼을 만드는 애플리케이션을 시작할 listBox1, 및 button1합니다. 사용자가 를 클릭하면 button1메서드는 button1_Click 목록 상자에 숫자 1~3을 추가하고 를 표시합니다 MessageBox. 사용자가 에서 아니요MessageBox를 클릭하면 메서드가 button1_Click 목록에 다른 숫자를 추가합니다. 사용자가 클릭 하면 , 애플리케이션이 호출 Exit, 큐에 남아 있는 모든 메시지를 처리 하 고 종료 됩니다.

이 예제에서는 및 button1listBox1 인스턴스화되어 양식에 배치되어야 합니다.

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 .NET Framework 2.0을 기준으로 사용되지 않는 및 Closing 이벤트를 발생 Closed 시키지 않습니다.

추가 정보

적용 대상

Exit(CancelEventArgs)

모든 메시지 펌프에 끝나야 함을 알리고 메시지가 처리된 후 모든 애플리케이션 창을 닫습니다.

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이 종료를 취소했는지 여부를 반환합니다.

추가 정보

적용 대상