Hi folks, what's the difference between background, foreground & main threads? What are the diff types of threads in .NET?
TIA
Hi folks, what's the difference between background, foreground & main threads? What are the diff types of threads in .NET?
TIA
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
A background thread is exactly that, it is a thread that is running in the background from the UI thread of an application. The UI thread in something like a winforms application is the thread responsible for repainting the UI and other user interactions.
Moving long running processes off to a background thread will help improve usability. Here is a good intro document to threading for you.
A background thread (whose Thread object has the Background
property set to true
) will
not prevent an application from quitting.
Once all normal 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.