Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: ee0bc0d176
Fetching contributors…

Cannot retrieve contributors at this time

64 lines (51 sloc) 1.8 kb
using System;
using System.Threading;
class EventTest
{
public static ManualResetEvent e;
// Code for first thread
public static void ThreadMethod_waiter_1()
{
Console.WriteLine("[Thread A] - Started.....");
Console.WriteLine("[Thread A] - I'm before wait for event .....");
e.WaitOne();
Console.WriteLine("[Thread A] - I'm after wait for event.");
}
// Code for second thread
public static void ThreadMethod_waiter_2()
{
Console.WriteLine("[Thread B] - Started.....");
Console.WriteLine("[Thread B] - I'm before wait for event .....");
e.WaitOne();
Console.WriteLine("[Thread B] - I'm after wait for event.");
}
// Code for 3th thread
public static void ThreadMethod_blocker()
{
Console.WriteLine("[Thread C] - Started.....");
Console.WriteLine("[Thread C] - Sleeping for 5000ms....");
Thread.Sleep(5000);
Console.WriteLine("[Thread C] - Setting the event....");
e.Set();
Console.WriteLine("[Thread C] - Finished.....");
}
public static void Main()
{
e = new ManualResetEvent(false);
// Create the waiter thread's group
Console.WriteLine("[ Main ] - Creating first thread..");
ThreadStart Thread_1 = new ThreadStart(ThreadMethod_waiter_1);
ThreadStart Thread_2 = new ThreadStart(ThreadMethod_waiter_2);
// Create the blocker thread
Console.WriteLine("[ Main ] - Creating second thread..");
ThreadStart Thread_3 = new ThreadStart(ThreadMethod_blocker);
Thread A = new Thread(Thread_1);
Thread B = new Thread(Thread_2);
Thread C = new Thread(Thread_3);
A.Start();
B.Start();
C.Start();
Thread.Sleep(500);
Console.WriteLine("[ Main ] - Finish...");
}
}
Jump to Line
Something went wrong with that request. Please try again.