A common asynchronous pattern is the pattern known as fork/join parallelism. This typically manifests by starting a number of pieces of work and later joining with that work.
A CountdownEvent
is initialized with a count. Threads can block waiting on the event until the count reaches 0
, at which point the CountdownEvent
will be set and the threads can proceed.
In this recipe, we will create a Console Application that performs some simulated work in a loop. We will initialize a CountdownEvent
to a small number of tasks, and then start simulating the work with the specified number of tasks. Each task will decrement the CountDownEvent
. When the CountDownEvent
reaches 0
and is signaled, we will reset the CountDownEvent
with a higher count and start over until we reach the maximum number of tasks.