AutoResetEvet 类里面的Set 方法
Set 方法在MSDN 说能够把该类的对象的状态设置为终止
然后让一个或多个等待的线程继续运行
但我不知道为什么不行
就只能让一个继续执行
class a
{
static AutoResetEvent myResetEvent = new AutoResetEvent(false);
public void F()
{
Console.WriteLine( "\n{0} is waiting for set ", Thread.CurrentThread.Name);
myResetEvent.WaitOne();
Console.WriteLine( "Accept! ");
}
public void EventSet()
{
Console.WriteLine( "Set! After 2 seconds ");
Thread.Sleep(2000);
myResetEvent.Set();
}
}
class b
{
static void Main()
{
a a = new a();
Thread newThread1 = new Thread(a.F);
newThread1.Name = "Thread1 ";
Thread newThread2 = new Thread(a.F);
newThread2.Name = "Thread2 ";
Thread newThread3 = new Thread(a.F);
newThread3.Name = "Thread3 ";
newThread1.Start();
newThread2.Start();
newThread3.Start();
Thread.Sleep(2000);
Console.WriteLine( "ThreadState : {0} {1} {2} ", newThread1.ThreadState,