我可能超出了 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/