Downlink background workers
We have a business example that's perfect for multiple BackgroundWorkers.
As an example, we have a form with a Save button. Typically we will run all save commands (Save Example) synchronously and then close the form. We would now like to split the work into separate threads using the backgroundworker.
We will skip each Save required (there may be many and / or different numbers of commands to be executed) by creating a BackgroundWorker for each command required.
The question is, how do we wait for ALL BackgroundWorkers to finish before closing the form. We understand how to wait for one BackgroundWorker to finish, but when we have X number of BackgroundWorkers running, how do we wait for all of them to finish before the UI form closes?
a source to share
I would recommend using the CountdownLatch class presented in the following (very excellent) MSDN Magazine article:
9 Reusable parallel data structures and algorithms
With SLaks in mind, pay attention to the BackgroundWorker events firing on the Completed
UI thread, this might be overkill.
a source to share