Waiting for Multiple Tasks
Parallel.Invoke method shown in the preceding section brings us to an interesting facility in the TPL. Did you see the one single most important difference compared to regular tasks? Here it is: Although the individual pieces of work passed to
Parallel.Invoke can run in parallel using asynchronous tasks, the sum of the parts is synchronous. That is,
Parallel.Invoke doesn’t return until all of its actions have been executed (or some error or cancellation has occurred).
If you read Chapter 29 carefully, you might immediately think of a way to achieve this kind of synchronizing behavior across multiple parallel actions. What about using events such as
ManualResetEvent or even the concept of a
CountDownEvent? Although ...