What is the difference between BackgroundWorker
and Thread
? In my application I am using a messaging system that communicates with the database regularly. Which one would I want to use here: BackgroundWorker
or Thread
?
7 Answers
A BackgroundWorker is a ready to use class in WinForms allowing you to execute tasks on background threads which avoids freezing the UI and in addition to this allows you to easily marshal the execution of the success callback on the main thread which gives you the possibility to update the user interface with the results. It also gives the possibility to track progress and cancel the task. It uses threads from the thread pool.
On the other hand a Thread is a class allowing you to simply execute some task on a new thread. It's a much more basic concept.

- 1,023,142
- 271
- 3,287
- 2,928
-
"BackgroundWorker is a ready to use class in WinForms". Not only WinForm, WPF and Console as well. – Yousha Aleayoub Apr 29 '20 at 13:55
While the BackgroundWorker
class isn't derived from the Thread
class it enables you to manage the work a thread does much more easily than if you created and invoked the thread yourself.
It raises three key events:
DoWork
- raised when the thread starts.ProgressChanged
- raised to report progress to the main UI thread.RunWorkerCompleted
- raised when the thread completes.
With these you can monitor the work the thread is doing after you call RunWorkerAsync()
to start it.

- 134,786
- 31
- 255
- 325
BackgroundWorker has already implemented functionality of reporting progress, completion and cancellation - so you don't need to implement it by yourself. Usage of Thread gives you more control over the async process execution (e.g. thread priority or choosing beetween foreground/background thread type).
BTW sometimes you don't need progress reporting and other BackgroundWorker stuff - so Thread/ThreadPool will be good alternative.

- 232,247
- 41
- 429
- 459
The BackgroundWorker
uses threads from the ThreadPool
, with Thread you create your own thread. Furthermore there is some facility in term of event reporting to the calling thread.

- 4,532
- 4
- 53
- 64

- 32,832
- 9
- 75
- 115
A BackgroundWorker is a thread implementation that allows you to assign assign a method to be done.
It gives you an communication API that allows you to stop the work, track the progress, and get notified Asynchronously.

- 48,127
- 24
- 147
- 185
Use BackgroundWorker - it anyway encapsulates thread and is simpler to work with. One of the advantage with it is that its api allows simpler event based model to report progress and further, those event calls get correctly routed to UI thread (so that you don't have to do marshal the call using Invoke method).

- 47,395
- 5
- 59
- 72
I think there is a big difference, that is When you want to use any UI component in methods called by BackgroundWorker, it doesn't work at all. I mean BackgroundWorker is a background process really and you won't be able to use interface actions. For example if you create a new label in method's going to call by BackgroundWorker, you catch an error definitely.

- 11