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
?
BackgroundWorker, is a component in . NET Framework, that allows executing code as a separate thread and then report progress and completion back to the UI.
The BackgroundWorker class allows you to run an operation on a separate, dedicated thread. Time-consuming operations like downloads and database transactions can cause your user interface (UI) to seem as though it has stopped responding while they are running.
BackgroundWorker is explicitly labeled as obsolete in .
BackgroundWorker makes the implementation of threads in Windows Forms. Intensive tasks need to be done on another thread so the UI does not freeze. It is necessary to post messages and update the user interface when the task is done.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With