线程同步中使用信号量AutoResetEvent
2014-11-02 09:54
204 查看
using System; using System.Threading; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { var p = new Program(); p.Do(); p.Signal(); } AutoResetEvent autoResetEvent = new AutoResetEvent(false); //false代表默认中阻塞状态 void Do() { var worker = new Thread(() => { Console.WriteLine("Start worker"); Console.WriteLine("wait"); autoResetEvent.WaitOne(); //等待信号 Console.WriteLine("do"); }); worker.Start(); } void Signal() { Console.WriteLine("Sent signal"); Console.ReadKey(); autoResetEvent.Set(); //发送信号 Console.ReadKey(); } } }
ManualResetEvent需要手动设定阻塞状态设置为false
相关文章推荐
- C#笔记20:多线程之线程同步中的信号量AutoResetEvent和ManualResetEvent
- C#笔记20:多线程之线程同步中的信号量AutoResetEvent和ManualResetEvent
- C#笔记20:多线程之线程同步中的信号量AutoResetEvent和ManualResetEvent
- 多线程之线程同步中的信号量AutoResetEvent和ManualResetEvent
- 线程02:多线程之线程同步中的信号量AutoResetEvent和ManualResetEvent
- C#笔记20:多线程之线程同步中的信号量AutoResetEvent和ManualResetEvent
- 改善C#程序的建议6:在线程同步中使用信号量
- Silverlight 2.0使用Lock, Interlocked, EventWaitHandle, Monitor来实现线程同步//C#线程同步的几种方法
- AutoResetEvent和ManualResetEvent 线程同步
- AutoResetEvent WaitOne和Set使用实例
- 多线程通中的AutoResetEvent与ManualResetEvent使用例子
- [转载]改善C#程序的建议6:在线程同步中使用信号量
- 线程同步(AutoResetEvent与ManualResetEvent)
- 线程同步 - EventWaitHandle & AutoResetEvent & ManualResetEvent
- 线程同步--使用信号量
- 改善C#程序的建议6:在线程同步中使用信号量
- 使用信号量的线程同步实验
- 改善C#程序的建议-在线程同步中使用信号量
- AutoResetEvent和ManualResetEvent的使用与区别
- 线程同步信号量的使用