"Go" WinForm Exit code: Application.exit and Environment.exit (0)

Source: Internet
Author: User

Application.exit and Environment.exit (0) What are the differences between the exits?

Application.exit: notifies the WinForm message loop to exit. Exits the app after all foreground threads have exited

Forced exit mode, just like Win32 's PostQuitMessage (). It means discarding all message pumps, expanding the call stack, and returning execution to the system

Method stops all message loops running on all threads and closes all windows of the application

Environment.exit: immediately terminates the current process and the application forces an exit. Returns ExitCode to the operating system,

By contrast, Environment.exit is more ruthless.

So we can construct the following restart () function to restart the application
private static void ReStart ()
{

Application.exit ();
System.Diagnostics.Process.Start (Application.executablepath);

}
This function cannot be done with Environment.exit

"Go" WinForm Exit code: Application.exit and Environment.exit (0)

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.