class Program
{ static void Main(string[] args)
{
var t = new Thread(()=>Process());
t.Start();
Console.WriteLine("老师等待提交试卷");
_StudentEvent.WaitOne();
Console.WriteLine("老师正在批阅英语试卷");
Thread.Sleep(TimeSpan.FromSeconds());
Console.WriteLine("老师批阅完成,打100分");
_TeacherEvent.Set();
Console.ReadKey();
}
static AutoResetEvent _StudentEvent = new AutoResetEvent(false);
static AutoResetEvent _TeacherEvent = new AutoResetEvent(false); static void Process(int seconds)
{
Console.WriteLine("学生开始考英语");
Thread.Sleep(TimeSpan.FromSeconds(seconds));
Console.WriteLine("学生交卷");
_StudentEvent.Set();
Console.WriteLine("等待老师批阅");
_TeacherEvent.WaitOne();
Console.WriteLine("学生领到试卷");
} }
05-27 10:18