I learned multithreading this week, recorded some ideas and learned things, and shared them with you. You are welcome to correct the incorrect description.
This section describes the foreground and background threads.
There is only one difference between the foreground thread and the background thread:
- Background thread: when the program ends, all background threads are immediately interrupted. Even if the background thread is running finally code. The terminated background thread does not expose exceptions. Unless the program is terminated by AppDomain. Unload.
- Front-end thread: When any front-end thread is running, the program will not end and will wait until the front-end thread ends,
The foreground Thread and background Thread can be converted at any time through Thread. IsBackground property.
All threads in the thread pool are backend threads.
The threads enabled by the unmanaged code are all background threads.
By default, all threads created using the new thread are foreground threads.