What is the difference between creating a thead using BackgroundWorker and creating a thread using System.Threading.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 ...
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.
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.
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.
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!)
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.
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