zoukankan      html  css  js  c++  java
  • 多线程11-AutoResetEvent

        class Program
        {
            private static AutoResetEvent workEvent = new AutoResetEvent(false);
            private static AutoResetEvent mainEvnet = new AutoResetEvent(false);
            static void Process(int second)
            {
                Console.WriteLine("a long run");
                Thread.Sleep(second);
                Console.WriteLine("work is done");
                workEvent.Set();
                Console.WriteLine("Wait for a main Thread to complete the work");
                mainEvnet.WaitOne();
                Console.WriteLine("starting second opeartion...");
                Thread.Sleep(5000);
                Console.WriteLine("Work is done");
                workEvent.Set();
            }
            static void Main()
            {
                var t = new Thread(() => Process(10));
                t.Start();
                Console.WriteLine("wait for another thread to complete work");
                workEvent.WaitOne();
                Console.WriteLine("First Operation is Complete");
                Console.WriteLine("Peffoming an operation on a mian thread");
                Thread.Sleep(TimeSpan.FromSeconds(5));
                mainEvnet.Set();
                Console.WriteLine("Now Runing the second Opeartion on an second thread");
                workEvent.WaitOne();
                Console.WriteLine("second opeartion is completed!");
            }
        }
  • 相关阅读:
    11、MyBatis教程之动态SQL
    10、MyBatis教程之一对多处理
    9、MyBatis教程之多对一处理
    8、MyBatis之使用注解开发
    7、MyBatis教程之分页实现
    6、MyBatis教程之日志实现
    5、MyBatis教程之ResultMap
    4、MyBatis教程之配置解析
    3、MyBatis教程之CURD操作
    Session的几种保存方式
  • 原文地址:https://www.cnblogs.com/shidengyun/p/5601719.html
Copyright © 2011-2022 走看看