Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 766
Icemanind Avatar asked Oct 24 '09 19:10

Icemanind


People also ask

What is the difference between BackgroundWorker and thread?

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

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.

What is UI thread and background thread?

A UI thread is an example of a foreground thread. The difference between background and foreground threads is pretty simple. Background threads don't stop a process from terminating, but foreground threads do. When the last foreground thread stops, then all the background threads are also stopped and the process ends.

What is WPF BackgroundWorker?

The BackgroundWorker class is used to run time-consuming tasks in the background; it leaves the user interface responsive. BackgroundWorker.rar. Sometimes we need to perform some time consuming tasks such as downloads etc.


2 Answers

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

like image 162
Christian C. Salvadó Avatar answered Sep 20 '22 17:09

Christian C. Salvadó


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.

like image 43
Mike Tours Avatar answered Sep 17 '22 17:09

Mike Tours