2 using System
.Threading
;
6 public static AutoResetEvent e
;
8 // Code for first thread
9 public static void ThreadMethod_waiter_1()
11 Console
.WriteLine("[Thread A] - Started.....");
12 Console
.WriteLine("[Thread A] - I'm before wait for event .....");
14 Console
.WriteLine("[Thread A] - I'm after wait for event.");
15 Console
.WriteLine("[Thread A] - I now set again the event to let other thread continue.");
19 // Code for second thread
20 public static void ThreadMethod_waiter_2()
22 Console
.WriteLine("[Thread B] - Started.....");
23 Console
.WriteLine("[Thread B] - I'm before wait for event .....");
25 Console
.WriteLine("[Thread B] - I'm after wait for event.");
26 Console
.WriteLine("[Thread B] - I now set again the event to let other thread continue.");
30 // Code for 3th thread
31 public static void ThreadMethod_blocker()
33 Console
.WriteLine("[Thread C] - Started.....");
34 Console
.WriteLine("[Thread C] - Sleeping for 5000ms....");
36 Console
.WriteLine("[Thread C] - Setting the event....");
38 Console
.WriteLine("[Thread C] - Finished.....");
42 public static void Main()
44 e
= new AutoResetEvent(false);
47 // Create the waiter thread's group
48 Console
.WriteLine("[ Main ] - Creating first thread..");
49 ThreadStart Thread_1
= new ThreadStart(ThreadMethod_waiter_1
);
50 ThreadStart Thread_2
= new ThreadStart(ThreadMethod_waiter_2
);
52 // Create the blocker thread
53 Console
.WriteLine("[ Main ] - Creating second thread..");
54 ThreadStart Thread_3
= new ThreadStart(ThreadMethod_blocker
);
56 Thread A
= new Thread(Thread_1
);
57 Thread B
= new Thread(Thread_2
);
58 Thread C
= new Thread(Thread_3
);
65 Console
.WriteLine("[ Main ] - Finish...");