AutoResetEvent 学生考试,老师阅卷,学生等待考试结果
class Program { static void Main(string[] args) { var t = new Thread(()=>Process(10)); t.Start(); Console.WriteLine("老师等待提交试卷"); _StudentEvent.WaitOne(); Console.WriteLine("老师正在批阅英语试卷"); Thread.Sleep(TimeSpan.FromSeconds(5)); 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("学生领到试卷"); } }