表示线程同步事件在一个等待线程释放后收到信号时自动重置.

 using System;
using System.Threading; // Visual Studio: Replace the default class in a Console project with
// the following class.
class Example
{
private static AutoResetEvent event_1 = new AutoResetEvent(true);
private static AutoResetEvent event_2 = new AutoResetEvent(false); static void Main()
{
Console.WriteLine("Press Enter to create three threads and start them.\r\n" +
"The threads wait on AutoResetEvent #1, which was created\r\n" +
"in the signaled state, so the first thread is released.\r\n" +
"This puts AutoResetEvent #1 into the unsignaled state.");
Console.ReadLine(); for (int i = ; i < ; i++)
{
Thread t = new Thread(ThreadProc);
t.Name = "Thread_" + i;
t.Start();
}
Thread.Sleep(); for (int i = ; i < ; i++)
{
Console.WriteLine("Press Enter to release another thread.");
Console.ReadLine();
event_1.Set();
Thread.Sleep();
} Console.WriteLine("\r\nAll threads are now waiting on AutoResetEvent #2.");
for (int i = ; i < ; i++)
{
Console.WriteLine("Press Enter to release a thread.");
Console.ReadLine();
event_2.Set();
Thread.Sleep();
} // Visual Studio: Uncomment the following line.
//Console.Readline();
} static void ThreadProc()
{
string name = Thread.CurrentThread.Name; Console.WriteLine("{0} waits on AutoResetEvent #1.", name);
event_1.WaitOne();
Console.WriteLine("{0} is released from AutoResetEvent #1.", name); Console.WriteLine("{0} waits on AutoResetEvent #2.", name);
event_2.WaitOne();
Console.WriteLine("{0} is released from AutoResetEvent #2.", name); Console.WriteLine("{0} ends.", name);
}
} /* This example produces output similar to the following: Press Enter to create three threads and start them.
The threads wait on AutoResetEvent #1, which was created
in the signaled state, so the first thread is released.
This puts AutoResetEvent #1 into the unsignaled state. Thread_1 waits on AutoResetEvent #1.
Thread_1 is released from AutoResetEvent #1.
Thread_1 waits on AutoResetEvent #2.
Thread_3 waits on AutoResetEvent #1.
Thread_2 waits on AutoResetEvent #1.
Press Enter to release another thread. Thread_3 is released from AutoResetEvent #1.
Thread_3 waits on AutoResetEvent #2.
Press Enter to release another thread. Thread_2 is released from AutoResetEvent #1.
Thread_2 waits on AutoResetEvent #2. All threads are now waiting on AutoResetEvent #2.
Press Enter to release a thread. Thread_2 is released from AutoResetEvent #2.
Thread_2 ends.
Press Enter to release a thread. Thread_1 is released from AutoResetEvent #2.
Thread_1 ends.
Press Enter to release a thread. Thread_3 is released from AutoResetEvent #2.
Thread_3 ends.
*/

构造函数

AutoResetEvent(Boolean)

用一个指示是否将初始状态设置为终止的布尔值初始化 AutoResetEvent 类的新实例。

Close()

释放由当前 WaitHandle 占用的所有资源。

(Inherited from WaitHandle)

CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。

(Inherited from MarshalByRefObject)

Dispose()

释放 WaitHandle 类的当前实例所使用的所有资源。

(Inherited from WaitHandle)

Dispose(Boolean)

当在派生类中重写时,释放 WaitHandle 使用的非托管资源,并且可选择释放托管资源。

(Inherited from WaitHandle)

Equals(Object)

确定指定的对象是否等于当前对象。

(Inherited from Object)

GetHashCode()

作为默认哈希函数。

(Inherited from Object)

GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。

(Inherited from MarshalByRefObject)

GetType()

获取当前实例的 Type

(Inherited from Object)

InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。

(Inherited from MarshalByRefObject)

MemberwiseClone()

创建当前 Object 的浅表副本。

(Inherited from Object)

MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。

(Inherited from MarshalByRefObject)

ToString()

返回表示当前对象的字符串。

(Inherited from Object)

WaitOne()

阻止当前线程,直到当前 WaitHandle 收到信号。

(Inherited from WaitHandle)

WaitOne(Int32)

阻止当前线程,直到当前 WaitHandle 收到信号,同时使用 32 位带符号整数指定时间间隔(以毫秒为单位)。

(Inherited from WaitHandle)

WaitOne(Int32, Boolean)

阻止当前线程,直到当前的 WaitHandle 收到信号为止,同时使用 32 位带符号整数指定时间间隔,并指定是否在等待之前退出同步域。

(Inherited from WaitHandle)

WaitOne(TimeSpan)

阻止当前线程,直到当前实例收到信号,同时使用 TimeSpan 指定时间间隔。

(Inherited from WaitHandle)

WaitOne(TimeSpan, Boolean)

阻止当前线程,直到当前实例收到信号为止,同时使用 TimeSpan 指定时间间隔,并指定是否在等待之前退出同步域。

(Inherited from WaitHandle)

Handle

获取或设置本机操作系统句柄。

(Inherited from WaitHandle)

SafeWaitHandle

获取或设置本机操作系统句柄。

(Inherited from WaitHandle)

IDisposable.Dispose()

释放由 WaitHandle 使用的所有资源。

(Inherited from WaitHandle)

WaitTimeout

指示在任何等待句柄终止之前 WaitAny(WaitHandle[], Int32, Boolean) 操作已超时。此字段为常数。

(Inherited from WaitHandle)

C# System.Threading.AutoResetEvent的更多相关文章

  1. System.Threading.Timer 定时器的用法

    System.Threading.Timer 是C# 中的一个定时器,可以定时(不断循环)执行一个任务.它是在线程上执行的,具有很好的安全性.为此  .Net Framework 提供了5个重载的构造 ...

  2. System.Threading.Timer的使用技巧

    转自:http://www.360doc.com/content/11/0812/11/1039473_139824496.shtml# System.Threading.Timer timer = ...

  3. C# System.Threading.Timer

    提供以指定的时间间隔对线程池线程执行方法的机制 using System; using System.Threading; class TimerExample { static void Main( ...

  4. c# 多线程之-- System.Threading Timer的使用

    作用:每隔多久去执行线程里的方法. class ThreadTimerDemo { static void Main(string[] args) { // Create an AutoResetEv ...

  5. System.Threading

    线程:定义为可执行应用程序中的基本执行单元. 应用程序域:一个应用程序内可能有多个线程. 上下文:一个线程可以移动到一个特定的上下文的实体 导入命名空间: //得到正在执行这个方法的线程 Thread ...

  6. .Net多线程编程—System.Threading.Tasks.Parallel

    System.Threading.Tasks.Parallel类提供了Parallel.Invoke,Parallel.For,Parallel.ForEach这三个静态方法. 1 Parallel. ...

  7. C# System.Threading.Timer 使用方法

    public class TimerHelper { System.Threading.Timer timer; public TaskSendMMS tasksendmms { get; set; ...

  8. C#中的线程四(System.Threading.Thread)

    C#中的线程四(System.Threading.Thread) 1.最简单的多线程调用 System.Threading.Thread类构造方法接受一个ThreadStart委托,改委托不带参数,无 ...

  9. C#错误之 System.Threading.ThreadAbortException:正在中止线程

    参考:http://www.cnblogs.com/chendaoyin/archive/2013/06/27/3159211.html 1.开启一个子线程 //开启一个子线程,子线程调用方法 Met ...

随机推荐

  1. 035 控制并发 select * from test1 where id =1 for update 就会对这行加锁了?

    今天在看同事程序的时候,看到这种用法,顺便学习下. 一:理论 1.功能 这个功能是上锁. 上的是一个排它锁,也就是说,其他的事务是可以读取的.但是不能写入或者更新. 二:实践 1.创建表 2.提交一条 ...

  2. 12306登录爬虫 session版本

    import requests import re import base64 # 定义session headers = { 'User-Agent':'Mozilla/5.0 (Windows N ...

  3. 大数据技术 - 通俗理解MapReduce之WordCount(三)

    上一章我们编写了简单的 MapReduce 程序,掌握这些就能编写大多数数据处理的代码.但是 MapReduce 框架提供给用户的能力并不止如此,本章我们仍然以上一章 word count 为例,继续 ...

  4. VMware5.5-vCenter Converter(转换)

    vCenter Converter 已知问题 出现:指定的参数不正确: "info.owner" 操作时一定是管理员,而不是管理员组的成员.或者: 如果 Converter Sta ...

  5. Codeforces.348D.Turtles(容斥 LGV定理 DP)

    题目链接 \(Description\) 给定\(n*m\)的网格,有些格子不能走.求有多少种从\((1,1)\)走到\((n,m)\)的两条不相交路径. \(n,m\leq 3000\). \(So ...

  6. 1490 ACM 数学

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1490 题意: 给出n*n 的矩阵,选出不同行不同列的n个元素,并求和: 如果所有选法所产生的和相等,则输出 ...

  7. NOIP考纲总结+NOIP考前经验谈

    首先来一张图,很直观(截止到2012年数据) 下面是收集的一些,我改了一下 红色加粗表示特别重要,必须掌握 绿色加粗表示最好掌握,可能性不是很大,但是某些可以提高程序效率 高精度 a.加法 b.减法 ...

  8. array中key所对应的value

    获取数组中的键对应的值 class Test{ public function index(){ $info = array( 'name' => 'daicr', 'age' => 24 ...

  9. 去除input默认带的上下按钮与修改placeholder的默认颜色、背景、placeholder内容的大小

    有时候需要用input元素中type属性值为number时,会出现默认的上下按钮, 去掉input默认的上下按钮:兼容性写法如下 input[type='number']::-webkit-outer ...

  10. mac上mysql8.0以tar.gz方式手动安装

    一.下载 官网地址: https://dev.mysql.com/downloads/mysql/ 选择:macOS 10.14 (x86, 64-bit), Compressed TAR Archi ...