WaitHandle——使用AutoResetEvent
来源:互联网 发布:软件推广策划案 编辑:程序博客网 时间:2024/06/14 17:59
区别ManualResetEvent:
使用AutoResetEvent和使用ManualResetEvent是完全相同的,只有一点区别:在使用autoresetevent时,在调用waitOne后,会自动执行到一个reset方法。
AutoResetEvent的waitone相当于将ManualResetEvent.waitone和reset合并为一个方法执行。
需要注意:autoresetevent的waitone和reset合并为了一个原子操作;
代码示例:
namespace 使用AutoResetEvent{ class Program { AutoResetEvent mre = new AutoResetEvent(false); static void Main(string[] args) { Thread.CurrentThread.Name = "main "; Program p = new Program(); Thread worker = new Thread(p.ThreadEntry); worker.Name = "worker"; worker.Start(); Console.WriteLine("main :start worker"); p.mre.Set(); Thread.Sleep(100); Console.WriteLine("main:worker go..."); p.mre.Set(); Thread.Sleep(100); } void ThreadEntry() { int i = 0; string name = Thread.CurrentThread.Name; while (i<10) { mre.WaitOne(); //这里实际上是waitone和reset************ Console.WriteLine("{0}:{1}---{2}",name ,i,DateTime .Now .Millisecond); i++; } } }}
0 0
- WaitHandle——使用AutoResetEvent
- WaitHandle——使用Mutex
- WaitHandle——使用ManualResetEvent
- WaitHandle——使用Semaphore
- 基元线程同步——内核模式构造(WaitHandle,EventWaitHandle,AutoResetEvent,ManualResetEvent,Semaphore,Mutex)
- WaitHandle、AutoResetEvent、ManualResetEvent整理
- c# 多线程-异步-WaitHandle-AutoResetEvent
- c# 多线程-异步-WaitHandle-AutoResetEvent
- 使用WaitHandle
- WaitHandle——解决线程同步问题
- 多线程中的锁系统(三)-WaitHandle、AutoResetEvent、ManualResetEvent
- WaitHandle 的使用.
- 使用WaitHandle和其他
- C# WaitHandle 使用教程
- AutoResetEvent使用
- WaitHandle
- ManualResetEvent和AutoResetEvent——多线程
- AutoResetEvent的使用
- 浙大计算机研究生复试上机考试-2010年
- Codeforces Round #285 (Div. 2) C. Misha and Forest
- 20150121Review
- 《GNU make项目管理》笔记--规则(2)
- java中如何用urlrewritefilter实现网站伪静态?
- WaitHandle——使用AutoResetEvent
- 编译Mesa10.3.5 /bin/bash: line 4: msgfmt: command not found
- uvaoj 12716 GCD XOR 打表
- 构造代码块、构造函数、this执行顺序
- 3d旋转点坐标计算公式
- Java中Set的使用
- spark内核揭秘-14-Spark性能优化的10大问题及其解决方案
- Linux下C语言检验文件权限 Linux stat函数详解
- Linus谈Linux