application.exit (); // notifies all message pumps that the pump must terminate and close all application windows after the message has been processed. // supported by the. NET Compact Framework. form.close (); // Close the window (the main program has not yet retired)
Points:
1. The program starts with Application.Run (new Form1), ends with Application.exit (), destroys the form, and reclaims the resources. In this case, if you open 1 forms, two statements are the same, if you open more than one, such as your Form1 and open the FORM2,FORM3 and so on, then you except the Application.Run () argument, do close is to close the form, the program does not exit, Application.exit is to close the entire program, including the window.
2. To exit the program and not exit in the main window, use Application.exit ();
If it is the main window, you can use this directly. Close ();
3.form.close (); is to close the current window, if there is only one window or MDI inside the main window is the exit program, is a safe type, and Application.exit (), it is forced to end the process, sometimes it must be used to use this exit is valid, such as when the thread locked, In general I think it is a good idea to use Form.close ().
4. When the Close method is called on a form that is displayed as a modeless window, you cannot call the Show method to make the form visible because the form's resources have been disposed. To hide the form and then make it visible, use the Control.hide method.
5. The form.closed and form.closing events are not raised when the Application.exit method is called to exit the application. If there is validation code in one of the events that must be performed, the Form.close method should be called separately for each open form before calling the Exit method.
C # windows and program exits