Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between BackgroundWorker and Thread?

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?

like image 941
Nighil Avatar asked Jan 21 '11 09:01

Nighil


People also ask

Is BackgroundWorker threaded?

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.

What is BackgroundWorker?

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.

Is BackgroundWorker obsolete?

BackgroundWorker is explicitly labeled as obsolete in .

What is use of BackgroundWorker in C#?

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.


1 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.

like image 173
Darin Dimitrov Avatar answered Oct 02 '22 21:10

Darin Dimitrov