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)