C # windows and program exits

Source: Internet
Author: User
Tags exit in

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.