在PC模式下暂停Consumer最简单的方法是什么?

发布于 2024-11-07 00:17:28 字数 147 浏览 4 评论 0原文

我有典型的生产者-消费者应用程序。我有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哥,最终变帅啦 2024-11-14 00:17:28

使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文