private static ManualResetEvent mre = new ManualResetEvent(false);
public static void Main()
Console.WriteLine("Instantiate a ManualResetEvent object as 'mre'\n");
Console.WriteLine("Start 2 threads that block;\n");
for(int i = 1; i <= 2; i++)
Thread t = new Thread(TestThread);
Console.WriteLine("\nPress Enter to call mre.Set() to release them");
Console.WriteLine("\nPress Enter to call mre.Reset(), for 2 new threads to call mre.WaitOne() and block");
for(int i = 3; i <= 4; i++)
Thread t = new Thread(TestThread);
Console.WriteLine("\nPress Enter to call mre.Set() and release them");
Console.WriteLine("\nPress Enter to run the last thread");
Thread t5 = new Thread(TestThread);
private static void TestThread()
string name = Thread.CurrentThread.Name;
Console.WriteLine(name + " starts, mre is 'set' so the thread does not block ");
Console.WriteLine(name + " ends");