views:

1231

answers:

2

What is the difference between creating a thead using BackgroundWorker and creating a thread using System.Threading.Thread?

+12  A: 

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!)

CMS
So basically, its just a wrapper for System.Threading.Thread designed to make threading a little simpler?
icemanind
http://stackoverflow.com/questions/1506838/backgroundworker-vs-background-thread/1507337#1507337
Matt Davis
+3  A: 

Background worker 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 apposed to starting up a brand new thread.

The main reason for using background worker is that is plugs in nicely with windows forms applications.

Mike Tours
+1 for accurately capturing the fact that background workers use the thread pool. In addition it is useful for people ot know that the BackgroundWorker is not a good choice if you need to call an STA Com object as the apartment cannot be set
Steve Sheldon