class Program
{
static CountdownEvent _countdownEvent =
new CountdownEvent(
2);
static
void PerformOperation(
string message,
int second)
{
Thread.Sleep(TimeSpan.FromSeconds(second));
Console.WriteLine(message);
_countdownEvent.Signal();
}
static
void Main()
{
Console.WriteLine(
"
Starting two operations
");
var t1 =
new Thread(() => PerformOperation(
"
Opearation1 is completed
",
4));
var t2 =
new Thread(() => PerformOperation(
"
Opeartion2 is compled
",
2));
t1.Start();
t2.Start();
_countdownEvent.Wait();
Console.WriteLine(
"
Both operations have been compled
"); _countdownEvent.Dispose(); } }