i 几乎没有混淆人工重整活动,等待一种方法,在下文中加以考虑。
static object objLock = new object();
static int counter = 5;
static ManualResetEvent mEvent = new ManualResetEvent(false);
static void Main(string[] args)
{
///LeftShifting(10, 4);
// RightShifting(3, 1);
// Xoring(0001, 1001);
// ExcahnageValuesWithXoring(10, 20);
// ReverseBits(0);
Thread.CurrentThread.Name = "Main Thread";
for(int i=0;i<5;i++)
{
Thread t = new Thread(new ThreadStart(DoSomeLongWork));
t.Name = i.ToString();
t.Start();
}
Console.WriteLine("Current thread is " + Thread.CurrentThread.Name);
mEvent.WaitOne();
Console.WriteLine("Current thread is " + Thread.CurrentThread.Name);
Console.WriteLine("Completed Long Running Process...");
Console.ReadLine();
}
private static void DoSomeLongWork()
{
Console.WriteLine("Starting Long Running Process...On " + Thread.CurrentThread.Name);
Thread.Sleep(5000);
Interlocked.Decrement(ref counter);
Console.WriteLine("Ending Long Running Process...On " + Thread.CurrentThread.Name);
if (counter == 0)
mEvent.Set();
}
我的问题是,我所说的话。 Waitone() 就是要阻止主食或执行儿童read。