Do TCP connection today, want to quit the program when the connection is not, use Application.exit () unexpectedly cannot exit, the program continues to execute down. Later found that application is not omnipotent, the method of Winfrom exit procedure generally has the following several
1.this. Close (); Just close the current window, if it is not the main form, you can not quit the program, and if there is a managed thread (not the main threads), also can not cleanly exit;
2.application.exit (); Forces all messages to abort, exits all forms, but does not cleanly exit if there is a managed thread (not the main thread);
3.application.exitthread (); Force abort all messages on the calling thread, as well as the problem that other threads cannot exit correctly;
4.system.environment.exit (0); This is the most thorough exit method, no matter what threads are forced to quit, the program ends very clean.
How to exit C # Winfrom programs