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

 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)

最新文章

  1. Kakfa重连测试
  2. Base64原理
  3. nodejs&amp;npm等概念梳理
  4. 驱动开发学习笔记. 0.07 Uboot链接地址 加载地址 和 链接脚本地址
  5. 记录一些容易忘记的属性 -- NSTimer
  6. 题目1444:More is better
  7. Java Servlet 工作原理问答
  8. TCP Linger的坑
  9. Oracle System密码忘记 密码修改、删除账号锁定lock
  10. Android项目svn代码管理问题
  11. hdu4745
  12. CUDA开发时用到的各种Linux命令
  13. spring auto-config
  14. HTML form表单小结
  15. 常用OJ名字+地址(自用)
  16. python之路--day13---函数--三元表达式,递归,匿名函数,内置函数-----练习
  17. linux软件管理
  18. Ubuntu Win10双系统重启ubuntu出现黑屏情况 Ubuntu引导修复
  19. 用canvas画一个等腰三角形
  20. python基础-----异常问题

热门文章

  1. P1026 统计单词个数 区间dp
  2. TensorFlow卷积层-函数
  3. detailFormatter bootstrapTable
  4. Java设计模式从精通到入门五 抽象工厂方法模式
  5. Redis基础、应用、第三方支持组件总结
  6. 【CRM】Microsoft CRM-QueryExpression 成员
  7. .net3.5 支持tuple
  8. BZOJ.1566.[NOI2009]管道取珠(DP 思路)
  9. AGC 030D.Inversion Sum(DP 期望)
  10. 洛谷P1541 乌龟棋(四维DP)