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!");
            }
        }
  • 相关阅读:
    Unity-WIKI 之 AllocationStats(内存分配)
    Unity-WIKI 之 DebugLine
    Unity-WIKI 之 DebugConsole
    Unity-WIKI 之 DrawArrow
    Unity 2D Sprite Lighting
    Unity 2D Touch Movement
    [Unity2D]2D Mobile Joystick
    DragRigidbody2D
    Finger Gestures 3.1
    2D Skeletal Animation Ready
  • 原文地址:https://www.cnblogs.com/shidengyun/p/5601719.html
Copyright © 2011-2022 走看看