• 多线程12-ManualResetEventSlim


        class Program
        {
            static ManualResetEventSlim manualRestEvnetSlim = new ManualResetEventSlim(false);
            static void TravelThroughGates(string threadName,int second)
            {
                Console.WriteLine("{0} falls to sleep", threadName);
                Thread.Sleep(TimeSpan.FromSeconds(second));
                Console.WriteLine("{0} waits for the gate open", threadName);
                manualRestEvnetSlim.Wait();
                Console.WriteLine("{0} enter the gates", threadName);
            }

            static void Main()
            {
                var t1 = new Thread(() => TravelThroughGates("T1"5));
                var t2 = new Thread(() => TravelThroughGates("T2"6));
                var t3 = new Thread(() => TravelThroughGates("T3"12));
                t1.Start();
                t2.Start();
                t3.Start();
                Thread.Sleep(TimeSpan.FromSeconds(6));
                Console.WriteLine("the Gates is open");
                manualRestEvnetSlim.Set();
                Thread.Sleep(TimeSpan.FromSeconds(2));
                manualRestEvnetSlim.Reset();
                Console.WriteLine("the gate has been closed");
                Thread.Sleep(TimeSpan.FromSeconds(10));
                Console.WriteLine("the gates opend second times");
                manualRestEvnetSlim.Set();
                Thread.Sleep(TimeSpan.FromSeconds(2));
                Console.WriteLine("the gates closed angin");
                manualRestEvnetSlim.Reset();

            }
        }
  • 相关阅读:
    零售定价(最终价格计算)(三)
    SAP数据表(一)商品表
    BizTalk 2006 R2 如何实现EDI报文的接收处理
    Simulate a Windows Service using ASP.NET to run scheduled jobs
    看曾士强评胡雪岩
    Smart Client Software Factory 初试
    Asp.net Dynamic Data之四定义字段的显示/编辑模板和自定义验证逻辑
    To set a 64bit mode IIS installation to 32bit mode
    集中日志查询平台方案(Draft)
    .net开发框架比较
  • 原文地址:https://www.cnblogs.com/shidengyun/p/5606830.html
Copyright © 2020-2023  润新知