. NetThread Pool
All the threads running in the thread pool are backend threads, and the isbackground attribute of the thread is set to true. The so-called backend threads mean that the running of these threads will not hinder the application.Program. On the contrary, the application can exit only after all foreground threads are finished.
Example
Using system; using system. collections. generic; using system. LINQ; using system. text; using system. threading; namespace multithreadtest {class program {static void main (string [] ARGs) {string taskobject = "running 10 seconds"; bool result = threadpool. queueuserworkitem (task, taskobject); If (! Result) console. writeline ("can't get thread"); else console. writeline ("press enter to exit"); console. read ();} static Void task (object state) {for (INT I = 0; I <10; I ++) {console. writeline (State + "thread ID is" + thread. currentthread. managedthreadid. tostring (); thread. sleep (1000 );}}}}
If you press any key during the program running, the program will be immediately aborted.
system. threading. the threadpool type encapsulates operations in the thread pool. Each process has a thread pool ,.. NET provides a thread pool management mechanism. You only need to insert the thread requirements into the thread pool, without having to ignore the subsequent work. All threads in the thread pool are backend threads and they will not hinder program exit.