多线程13-CountdownEvent

    class Program
    {
        static CountdownEvent _countdownEvent = new CountdownEvent(2);
        static void PerformOperation(string message,int second)
        {
            Thread.Sleep(TimeSpan.FromSeconds(second));
            Console.WriteLine(message);
            _countdownEvent.Signal();
        }
        static void Main()
        {
            Console.WriteLine("Starting two operations");
            var t1 = new Thread(() => PerformOperation("Opearation1 is completed"4));
            var t2 = new Thread(() => PerformOperation("Opeartion2 is compled"2));
            t1.Start();
            t2.Start();
            _countdownEvent.Wait();
            Console.WriteLine("Both operations have been compled");
            _countdownEvent.Dispose();
        }
    }
posted @ 2016-06-22 14:03  shidengyun  阅读(232)  评论(0编辑  收藏  举报