|
|
Posted on 12/14/2015 6:28:16 PM
|
|
|

Key points:
1. When a thread is created in the main thread, the IsBackground of the thread is set to FALSE by default.
2. When the main thread exits, the thread with IsBackground=FALSE will continue to execute until the thread execution ends.
3. Only threads with IsBackground=TRUE will exit with the exit of the main thread.
4. When initializing a thread and setting Thread.IsBackground=true, it indicates that the thread is a background thread. The background thread will exit as the main thread exits.
5. Principle: As long as all the foreground threads are terminated, the CLR will call Abort() to each active background thread to completely terminate the application.
Attached is an other: How to exit the program: this. Close(); If you just close the current window, if it is not the main form, you cannot exit the program, and if there is a managed thread (not the main thread), you cannot exit cleanly; Application.Exit(); Force all messages to abort and exit all forms, but if there is a managed thread (not the main thread), it cannot exit cleanly; Application.ExitThread(); forcibly abort all messages on the calling thread, and also face the problem that other threads cannot exit correctly; System.Environment.Exit(0); This is the most complete way to exit, no matter what thread is forced to quit, ending the program very cleanly. |
Previous:Use Newtonsoft.Json in .NET to convert, read, write jsonNext:Full parsing of dangerous functions in PHP
|