zoukankan      html  css  js  c++  java
  • 多线程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();

            }
        }
  • 相关阅读:
    Linux命令大全
    paramiko 使用总结(SSH 操作远端机器)
    Django之ModelForm详解
    django模板之forloop
    学习VUE笔记及遇到的坑
    bootstrap table加载失败
    使用RedisTemplate遇到的坑
    grunt 不是内部或外部命令,也不是可运行的程序或批处理文件
    SpringBoot关于系统之间的远程互相调用
    数据在网络中的传输
  • 原文地址:https://www.cnblogs.com/shidengyun/p/5606830.html
Copyright © 2011-2022 走看看