Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How often do you use System.Component.BackgroundWorker in your UIs ? (if ever)

I am sure a responsive UI is something that everyone strives for and the reccomended way to do stuff is to use the BackgroundWorker for this.

Do you find it easy to work with ? Do you use it often ? Or do you have your own frameworks for lengthy tasks and reporting process.

I have found that I am using it quite a lot and even using its delegates wherever I need some sort of progress reporting.

like image 818
Tomas Pajonk Avatar asked Sep 08 '08 14:09

Tomas Pajonk


4 Answers

Multithreaded programming is hard to grasp in the beginning (and veterans still fail sometimes) and BackgroundWorker makes it a bit easier to use. I like the fact that BackgroundWorker has functionality which is easy to implement but even easier to wrongly implement in a subtle way, like cancellation. I use it if I have and need a progress update, so I can display a meaningful progress bar.

If not, I use a Thread (or borrow from the ThreadPool), because I don't need all the functionality of BackgroundWorker and am proficient enough with threads to start a Thread and wait for it to stop.

As for delegates for non-related tasks, I use those of the Thread classes, like plain void ThreadStart(), or I create my own.

like image 173
DonkeyMaster Avatar answered Nov 11 '22 08:11

DonkeyMaster


BackgroundWorker makes things a lot easier. One thing I found the hard way is Backgroundworker itself has thread affinity even though it is supposed to hide the thread switching problem. It does not automatically switch to the UI thread in every case. It needs to be created and run from the UI thread for thread switching to happen properly.

like image 25
Gulzar Nazim Avatar answered Nov 11 '22 09:11

Gulzar Nazim


I use it quite often for tasks such as progress indication and background data loading\processing.
Recently i found use case that is not supported out of box. It's "Overridable Task". However Patric Smacchia come up with nice solution.

like image 1
aku Avatar answered Nov 11 '22 08:11

aku


I've used it once and was quite happy with it. Often, there is no need for "big" multithreading, but only for 2 Threads (UI and Worker), and it works really well without having to worry too much about the underlying Threading Logic.

like image 1
Michael Stum Avatar answered Nov 11 '22 07:11

Michael Stum