using System;
using System.Threading;
namespace ConsoleApplication1
{
class Program
{
public static ManualResetEvent mre = new ManualResetEvent(false);
static void Main(string[] args)
{
Thread newThread = new Thread(new ThreadStart(NewThread));
newThread.Name = "新线程";
newThread.Start();
mre.Set();
Console.WriteLine("Main 函数结束。");
}
static void NewThread()
{
Console.WriteLine("新线程: waiting for an event");
mre.WaitOne();
Console.WriteLine("新线程: got an event");
Console.WriteLine(DateTime.Now);
Thread.Sleep(2000); //延时两秒
Console.WriteLine(DateTime.Now);
Console.WriteLine("新线程已执行完。。");
Console.WriteLine();
}
}
}
Result: