Foreground and Background Threads

A managed thread is either a background thread or a foreground thread. Background threads are identical to foreground threads with one exception: a background thread will not keep the managed execution environment alive. Once all foreground threads have been stopped in a managed process (where the .exe file is a managed assembly), the system stops all background threads and shuts down. A thread can be designated as a background or a foreground thread by setting the Thread.IsBackground property. For example, a thread can be designated a background thread by setting Thread.IsBackground to true. A thread can likewise be designated a foreground thread by setting IsBackground to false. 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 create a foreground thread that you want to listen for some activity, such as a socket connection, you should set Thread.IsBackground to true, so that your process can terminate.

See Also

Thread.IsBackground | Thread | ThreadAbortException