zoukankan      html  css  js  c++  java
  • AutoResetEvent和ManualResetEvent用法示例

    using System;
    using System.Threading;

    namespace ResetEvent{

    public class EntryPoint{
    static AutoResetEvent auto = new AutoResetEvent(false);
    static ManualResetEvent manual = new ManualResetEvent(false);
    static EventWaitHandle eventWait = new EventWaitHandle(false,EventResetMode.AutoReset);

    public static void Main(string[] args){
    eventWait = auto;
    ManualResetEventMethodRun();
    // AutoResetEventMethodRun();
    }
    #region AutoResetEventMethod

    static void AutoResetEventMethodRun(){
    Thread t = new Thread(AutoResetEventMethod);
    Console.WriteLine("AutoResetEvent Main Begin...");
    t.Start();
    Thread.Sleep(5000);
    auto.Set();
    // Thread.Sleep(5000);
    Console.WriteLine("AutoResetEvent Main End...");
    Console.Read();
    }
    static void AutoResetEventMethod(){
    Console.WriteLine("AutoResetEvent Sub Begining......");
    auto.WaitOne();
    // auto.Set();
    Console.WriteLine("AutoResetEvent to do something 1......");
    auto.WaitOne();
    Console.WriteLine("AutoResetEvent to do something 2......");
    Console.WriteLine("AutoResetEvent Sub Ending......");

    }

    #endregion

    #region ManualResetEventMethod

    static void ManualResetEventMethodRun(){
    Thread t = new Thread(ManualResetEventMethod);
    Console.WriteLine("ManualResetEventMethod Main Begin...");
    t.Start();
    Thread.Sleep(5000);
    manual.Set();
    // Thread.Sleep(5000);
    Console.WriteLine("ManualResetEventMethod Main End...");
    Console.Read();
    }

    static void ManualResetEventMethod()
    {
    Console.WriteLine("ManualResetEventMethod Sub Begining......");
    manual.WaitOne();
    Console.WriteLine("ManualResetEventMethod to do something 1......");
    manual.Reset();
    manual.WaitOne();
    Console.WriteLine("ManualResetEventMethod to do something 2......");
    Console.WriteLine("ManualResetEventMethod Sub Ending......");
    }
    #endregion
    }

    }

  • 相关阅读:
    js 导航栏多项点击显示下拉菜单代码
    当你工作与生活迷茫时可以来看看 shuke
    vs code使用指南
    两列
    三列浮动中间宽度自适应
    两列右列宽度自适应
    word文档巧替换(空行替换、空格替换、软回车替换成硬回车)
    统计单元格内指定的字符数方法 ,方法 一好用
    umi ui 构建时出现 spawn sh ENOENT 报错的解决方法
    新的博客,声明一下以前的域名作废了
  • 原文地址:https://www.cnblogs.com/zhangchenliang/p/2653268.html
Copyright © 2011-2022 走看看