Thread 等待异步方法执行完成方案:AutoResetEvent.WaitOne()
Thread 等待异步方法执行完成方案:AutoResetEvent.WaitOne()
static AutoResetEvent myresetevent = new AutoResetEvent(false); static int number = 0; static void Main(string[] args) { Thread thread = new Thread(new ThreadStart(myfunc)); thread.Name = "aaa"; thread.Start(); var time = 10; for (int i = 0; i < time; i++) { myresetevent.WaitOne(); number++; Console.WriteLine("number:{0}", number); } } static void myfunc() { Thread.Sleep(3000); if(true) //while (true) { number += 10; Console.WriteLine("线程number:{0}", number); myresetevent.Set(); } }