在PC模式下暂停Consumer最简单的方法是什么?
我有典型的生产者-消费者应用程序。我有 BlockingCollection 来提供生产-消费机制。我需要的是添加从另一个线程暂停消费者线程执行的能力。我已经阅读了不同的 .net 同步原语,但我无法决定如何以最简单的方式实现它。
PS:我使用.net 4.0。
I have typical producer-consumer application. I have BlockingCollection to provide producing-consuming mechanism. What I need is to add ability to pause consumer thread execution from another thread. I've read about different .net synchronization primitives but I can't decide how to implement it in the easiest way.
P.S.: I use .net 4.0.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 AutoResetEvent 并在 Consumer 中等待它,直到另一个线程通过将其设置为有信号来再次唤醒它。
Use an AutoResetEvent and wait on it in the Consumer until the other thread wakes it up again, by setting it to signaled.