using System;
using System.Threading;
namespace AutoResetEvent_Examples
{
class MyMainClass
{
const int numIterations = 10;
static AutoResetEvent myResetEvent = new AutoResetEvent(false);
static int number;
static void Main()
{
Thread myReaderThread = new Thread(new ThreadStart(MyReadThreadProc));
myReaderThread.Name = "ReaderThread";
myReaderThread.Start();
for (int i = 1; i <= numIterations; i++)
{
Console.WriteLine("Writer thread writing value: {0}", i);
number = i;
myResetEvent.Set();
Thread.Sleep(0);
}
myReaderThread.Abort();
Console.ReadKey();
}
static void MyReadThreadProc()
{
while (true)
{
myResetEvent.WaitOne();
Console.WriteLine("{0} reading value: {1}", Thread.CurrentThread.Name, number);
}
}
}
}