using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace ManualResetEventState
{
class Program
{
static ManualResetEvent _mre = new ManualResetEvent(false);
static void Main(string[] args)
{
Console.WriteLine("输入1为Set() 开始运行");
Console.WriteLine("输入2为Reset() 暂停运行");
Thread[] _threads = new Thread[3];
for (int i = 0; i < _threads.Count(); i++)
{
_threads[i] = new Thread(ThreadRun);
_threads[i].Start();
}
while (true)
{
switch (Console.ReadLine())
{
case "1":
_mre.Set();
Console.WriteLine("开始运行");
break;
case "2":
_mre.Reset();
Console.WriteLine("暂停运行");
break;
default:
break;
}
}
}
static void ThreadRun()
{
int _threadID = 0;
while (true)
{
_mre.WaitOne();
_threadID = Thread.CurrentThread.ManagedThreadId;
Console.WriteLine("current Tread is " + _threadID);
Thread.Sleep(TimeSpan.FromSeconds(2));
}
}
}
}