C#多线程问题,如何知道所有的线程都执行完毕

如题所述

这个需求有很多方法可以实现,给你一个最简单的方法的例子:

using System;using System.Threading;public class ThreadDemo{ static void Main() { Console.WriteLine("Hello, I'm going to do some time-consuming work..."); for (int i = 0; i < 5; i++) { Thread t = new Thread(Work); t.Start(); t.Join(); } Console.WriteLine("I'm finished all works on my hand. You can do something else."); // Some other works. } static void Work() { // Simulate time-consuming work Thread.Sleep(1000); Console.WriteLine("Working..."); }}
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答