Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are background, foreground & main threads?

what's the difference between background, foreground & main threads? What are the diff types of threads in .NET?

like image 312
SoftwareGeek Avatar asked Feb 04 '23 06:02

SoftwareGeek


2 Answers

A background thread (whose Thread object has the Background property set to true) will not prevent an application from quitting.

Once all normal(foreground) threads have exited, any running background threads are immediately terminated. In addition, if an AppDomain is unloaded, all background threads in the AppDomain are immediately aborted.

The threads managed by the ThreadPool are background threads.

A foreground thread is an ordinary thread.

The main thread is the initial thread that started the program. (The thread running the Main method)

For more information, see here.

like image 89
SLaks Avatar answered Feb 07 '23 19:02

SLaks


The distinction is succinctly stated in the documentation. Background threads are interrupted when the program ends.

http://msdn.microsoft.com/en-us/library/h339syd0(VS.71).aspx

like image 44
BC. Avatar answered Feb 07 '23 17:02

BC.