2007-12-06 Jb Evain <jbevain@novell.com>
[mono.git] / mono / tests / manualresetevents.cs
blob9c5b6981dda72a4ff422911f46d1191ef0a3e774
1 using System;
2 using System.Threading;
4 class EventTest
5 {
6 public static ManualResetEvent 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 .....");
13 e.WaitOne();
14 Console.WriteLine("[Thread A] - I'm after wait for event.");
17 // Code for second thread
18 public static void ThreadMethod_waiter_2()
20 Console.WriteLine("[Thread B] - Started.....");
21 Console.WriteLine("[Thread B] - I'm before wait for event .....");
22 e.WaitOne();
23 Console.WriteLine("[Thread B] - I'm after wait for event.");
26 // Code for 3th thread
27 public static void ThreadMethod_blocker()
29 Console.WriteLine("[Thread C] - Started.....");
30 Console.WriteLine("[Thread C] - Sleeping for 5000ms....");
31 Thread.Sleep(5000);
32 Console.WriteLine("[Thread C] - Setting the event....");
33 e.Set();
34 Console.WriteLine("[Thread C] - Finished.....");
38 public static void Main()
40 e = new ManualResetEvent(false);
43 // Create the waiter thread's group
44 Console.WriteLine("[ Main ] - Creating first thread..");
45 ThreadStart Thread_1 = new ThreadStart(ThreadMethod_waiter_1);
46 ThreadStart Thread_2 = new ThreadStart(ThreadMethod_waiter_2);
48 // Create the blocker thread
49 Console.WriteLine("[ Main ] - Creating second thread..");
50 ThreadStart Thread_3 = new ThreadStart(ThreadMethod_blocker);
52 Thread A = new Thread(Thread_1);
53 Thread B = new Thread(Thread_2);
54 Thread C = new Thread(Thread_3);
56 A.Start();
57 B.Start();
58 C.Start();
60 Thread.Sleep(500);
61 Console.WriteLine("[ Main ] - Finish...");