Synchronous work in BackgroundWorker

My application takes a lot of time regardless of multiple files. I created a BackgroundWorker to pipe work to each file, but it seems that the backgroundwork is capable of doing asynchronous work. Is it possible to perform multiple asynchronous tasks in unison with it, or is there a similar object for performing synchronous operations?

+1


source to share


3 answers


The background worker is usually used to refresh the UI and / or to quit, so you don't block the UI when the process starts for a long time. This means that you "hand off" the "file work" to a background worker process, and then use a callback to update the user interface (usually), during which time your APP remains responsive.



If the items are independent, you may want to create multiple threads to separate the work. Again, if I understand you correctly. If I am then, you might want to check out Jon Skeet's thread article .

+2


source


As long as you can use BackgroundWorker, I think you just need to spin up multiple threads to get the job done. One thread (possibly the main thread) will create and start these worker threads, and then do the merge for all workers to wait for processing to complete.



Alternatively, if you are using .Net 3.5, have a look at Parallel Extensions for. Net . The Task object from this library is probably ideal for your situation.

+1


source


You can perform multiple asynchronous tasks by creating more than one BackgroundWorker object in your code. We created a JobPool class that created a few BackgroundWorker objects to run so that we can control the total running at any given time. But if there are only a few files that you will be processing, it will be overkill.

0


source







All Articles