.net - 检查AutoResetEvent状态

标签 .net multithreading autoresetevent

是否可以检查AutoResetEvent对象的实际处理方式?是由超时触发,还是从其他方法调用Set()触发了?

这是我的代码。

private AutoResetEvent autoResetEvent = new AutoResetEvent(false);
private int timeout = 30000;

public void SyncMethod()
{
    // some code before
    autoResetEvent.WaitOne(timeout);
    // if autoResetEvent called by timeout then { do some stuff } 
    // some code after
}
public void AsyncMethod()
{
    // some code before
    // ok I am done
    autoResetEvent.Set();
}

最佳答案

WaitHandle::WaitOne方法(Int32)

返回值类型:System::Boolean

如果当前实例接收到信号,则为true;否则为true。否则为假。

因此,超时后返回false。

关于.net - 检查AutoResetEvent状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11508908/

相关文章:

.net - 制作 "hotkey"以在 WPF 中聚焦 TextBox

c# - 如何在 Visual Studio 2010 中查看调试输出?

.net - 转义 +(加号)在 URI

java - Java中volatile和synchronized的区别

c# - 生产者-消费者同步问题

c# - AutoResetEvent/ManualResetEvent 消耗什么资源?

.net - 如何转义 LIKE 子句?

java - 如何创建一个监听状态变化的线程?

python - ThreadPoolExecutor 线程数

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