This article is a mirror article of machine translation, please click here to jump to the original article.

View: 20103|Reply: 0

[Source] Thread multithreading The important role of IsBackground for threads

[Copy link]
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 json
Next:Full parsing of dangerous functions in PHP
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com