using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { List<Task> taskList = new List<Task>(); taskList.Add( Task.Factory.StartNew(()=> { Thread.Sleep(1000); Console.WriteLine("1秒执行结束"); })); taskList.Add(Task.Factory.StartNew(() => { Thread.Sleep(800); Console.WriteLine("o.8秒执行结束"); })); Console.WriteLine("执行中"); TaskFactory taskFactory = new TaskFactory(); taskList.Add(taskFactory.ContinueWhenAll(taskList.ToArray(), tArray => { Thread.Sleep(200); Console.WriteLine("等待这些完成后执行"); })); //Console.WriteLine("执行完成"); Console.Read(); } } }
时间: 2024-10-20 06:16:26