Start a number of threads of the program in the shutdown when there is a problem, if the program exits without closing the thread, then the thread will always exist, but most of the start of the thread are local variables, can not be closed, if the call Thread.CurrentThread.Abort () Method closes the main thread, a ThreadAbortException exception appears, so this is not possible.
Later found this approach: Thread.IsBackground set the thread as a background thread.
MSDN explains foreground and background threads: Managed threads or background threads, or foreground threads. Background threads do not make the managed execution environment active, except that the background thread is the same as the foreground thread. Once all foreground threads are stopped in the managed process (where the. exe file is the managed assembly), all background threads are stopped and closed. By setting the Thread.IsBackground property, you can designate a thread as either a background thread or a foreground thread. For example, you can designate a thread as a background thread by setting Thread.IsBackground to True. Similarly, by setting IsBackground to False, you can designate a thread as a foreground thread. All threads that enter the managed execution environment from unmanaged code are marked as background threads. All threads generated by creating and starting a new thread object are foreground threads. If you want to create a foreground thread that you want to use to listen for certain activities, such as a socket connection, you should set the Thread.IsBackground to true so that the process can terminate.
So the solution is to set: Thread.CurrentThread.IsBackground = True when the main thread is initialized;
In this way, the main thread is a background thread, which closes all threads when the main program is closed and the main thread is closed. But in this case, all the threads that are executing are forced to close, so the results of the thread's work are saved at shutdown time.
--excerpt from the C # programming dictionary