c# - AutoResetEvent 仅在未设置该次数时等待的最佳方法

标签 c# multithreading autoresetevent

我可能超出了 AutoResetEvent 的正确设计范围,但不太清楚该求助于什么。我想要这种行为:

var autoResetEvent = new AutoResetEvent(false);
autoResetEvent.Set();
autoResetEvent.Set();
autoResetEvent.WaitOne();
// since Set was called twice, I don't want to wait here
autoResetEvent.WaitOne();

不幸的是(对于我的问题),这不是 AutoResetEvent 的行为方式。对于这种情况,最好使用什么类?

注意:我可以访问 .NET Parallel Exensions 库。

最佳答案

您是否在寻找 Semaphore

关于c# - AutoResetEvent 仅在未设置该次数时等待的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4147981/

相关文章:

c# - 是否有一个 WaitOne 方法本质上首先调用 Reset?

c# - 月历显示日期为周一至周日

c# - 使用 ToArgb() 后跟 FromArgb() 不会产生原始颜色

javascript - 如何使用 Ajax 将 WebSocket 数据从 View 发送到 Controller 以及将修改后的数据发送到 View

java - Java的事前关系?

c# - 如何避免 Safe handle has been closed

c# - 为什么要限制方法和属性继承的返回类型以致不允许后代?

multithreading - 从 WorkerThread 到 MFC 中的主窗口的 PostMessage

c# - 线程暂停和恢复 C#

.net - 在不影响事件的情况下检查 AutoResetEvent 的值