标签:data ati event actor net eve style factory 一个
1 static void Main(string[] args) 2 { 3 CountdownEvent countdown = new CountdownEvent(3); 4 int taskid = 1; 5 for (var i = 0; i < 3; i++) 6 { 7 Task.Factory.StartNew(() => 8 { 9 int cur = taskid++; 10 Console.WriteLine($"Task[{cur}] is Running"); 11 Thread.Sleep(taskid * 1000); 12 countdown.Signal(); 13 Console.WriteLine($"Task[{cur}] exit"); 14 }); 15 } 16 Console.WriteLine($"Main wait"); 17 countdown.Wait(); 18 Console.WriteLine($"Main exit"); 19 Console.ReadKey(); 20 }
CountdownEvent 与Barrier类似,但是在多次等待中,使用Barrier更加方便。
标签:data ati event actor net eve style factory 一个
原文地址:https://www.cnblogs.com/deepminer/p/9053493.html