是否可以检查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/