Difference between BackgroundWorker and System.Threading.Thread
What is the difference between开发者_如何转开发 creating a thead using BackgroundWorker and creating a thread using System.Threading.Thread?
The BackgroundWorker class basically abstracts the Thread creation and monitoring process, and gives you an event-driven API to report the progress of the operation (ProgressChanged) and determine when your operation is finished (RunWorkerCompleted)...
One of the most common uses for it is to keep a Windows GUI responsive while a long-running process executes in the background. So basically, its just a wrapper for System.Threading.Thread designed to make background threading a little simpler (as the name implies!)
BackgroundWorker
is actually a wrapper for asynchronous thread invocation via delegates - using reflector one can see it calls the begin/end invoke methods accordingly. This differs from a System.Threading.Thread
in that it uses the threadpool as opposed to starting up a brand new thread.
The main reason for using background worker is that it plugs in nicely with windows forms applications.
精彩评论