views:

502

answers:

2

What is difference between a background and foreground thread ?

+9  A: 

From MSDN:

Background threads are identical to foreground threads with one exception: a background thread does not keep the managed execution environment running.

Matthew Jones
You mean that it cannon prevent a current process from terminating...
Guffa
@Guffa: I don't understand. You're quibbling over an interpretation of the MSDN documentation?
yodaj007
+6  A: 

See this page:

  • Foreground threads have the ability to prevent the current application from terminating. The CLR will not shut down an application (which is to say, unload the hosting AppDomain) until all foreground threads have ended.

  • Background threads (sometimes called daemon threads) are viewed by the CLR as expendable paths of execution that can be ignored at any point in time (even if they are currently laboring over some unit of work). Thus, if all foreground threads have terminated, any and all background threads are automatically killed when the application domain unloads.

Zed