c# 线程池中使用AutoResetEvent(事件)
来源:互联网 发布:windows查询监听端口 编辑:程序博客网 时间:2024/05/22 12:23
using System;
using System.Threading;
namespace program
{
class wangjun
{
static void Main(string[] args)
{
//构建一个AutoResetEvent对象(刚开始它没有收到信号)
AutoResetEvent are = new AutoResetEvent(false);
//告诉线程池等待AutoResetEvent对象
RegisteredWaitHandle rwh = ThreadPool.RegisterWaitForSingleObject(
are, //等待AutoResetEvent对象
EventOperation, //回调该方法
null, //将null传递给EventOperation
5000, //用5秒种时间等待事件发送信号
false //每一次当事件的信号被发送后都调用EventOperation方法
);
//进入循环
Char operation;
do
{
Console.WriteLine("S=Signal Q=Quit? ");
operation = char.ToUpper(Console.ReadKey(true).KeyChar);
if (operation == 'S')
{
are.Set();
}
} while (operation !='Q');
}
//一旦事件的信号已被发送,或者最后一个信号或超时值已经过去了5秒钟,就调用这个方法
private static void EventOperation(object state, Boolean timeout)
{
if (timeout)
{
Console.WriteLine("Timedout while waiting for the AutoResetEvent. ");
}
else
{
Console.WriteLine("The AutoResetEvent became signaled. ");
}
}
}
}
- c# 线程池中使用AutoResetEvent(事件)
- C#中AutoResetEvent的使用
- c#中利用 AutoResetEvent和ManualResetEvent实现线程同步
- C#线程控制ManualResetEvent和AutoResetEvent
- C#信号的使用方法---c#中AutoResetEvent
- 线程同步之AutoResetEvent的使用
- C# AutoResetEvent
- C#关于AutoResetEvent的使用介绍[转载]
- C#关于AutoResetEvent的使用介绍
- C#关于AutoResetEvent的使用介绍
- C#关于AutoResetEvent的使用介绍[转载]
- C#关于AutoResetEvent的使用介绍
- C#关于AutoResetEvent的使用介绍[转载]
- C#关于AutoResetEvent的使用介绍[转载]
- C#关于AutoResetEvent的使用介绍[转载]
- C#关于AutoResetEvent的使用介绍
- C#中使用事件
- C#多线程同步事件及等待句柄AutoResetEvent 和 ManualResetEvent
- 我的心得
- 设计模式使用原则
- java线程:中止(interrupt)!=stop
- 真是白痴啊
- 连接数据库
- c# 线程池中使用AutoResetEvent(事件)
- 北邮复试上机自测题
- Java中异常处理
- 栈的简单操作
- FreeTextBox使用方法
- 大本营更新公告2010年第12周(3月22日~3月26日)
- 多态,抽象类,接口
- 说
- 面向对象编程:封装与继承