|
1
beginner
0
intermediate
0
advanced
|
|||
|
||||
|
CountdownEvent is a synchronization primitive that unblocks its waiting threads after it has been signaled a certain number of times. E.g. if we create a CountdownEvent with a parameter of 3, threads waiting on it will remain blocked until a Signal event is called 3 times.
static CountdownEvent countdownEvent= new CountdownEvent (3);
static void Main()
{
new Thread (Func).Start (1);
new Thread (Func).Start (2);
new Thread (Func).Start (3);
countdownEvent.Wait(); // The thread will block until we receieve three Signals.
Console.WriteLine("Three Signals received. Now I can proceed");
}
static void Func (object id)
{
Thread.Sleep((int)id * 1000);
Console.WriteLine("Signalling");
countdownEvent.Signal();
}
Notes:
CountdownEvent is available only in .net framework 4.0 and above |
|||
|
||||