有没有办法确定EventWaitHandle
是通过拨打Set();
发出信号还是已超时?一个例子:
private static EventWaitHandle ThreadWaiter =
new EventWaitHandle(false, EventResetMode.AutoReset);
private void StartLongAction()
{
ThreadWaiter.WaitOne(5000);
//detect signal reason
if(ThreadWaiter was signaled)
{
}
//detect signal reason
else if(ThreadWaiter was timedout)
{
}
}
public void HardwareEvent(EventArgs e)
{
ThreadWaiter.Set();
}
我能想到的唯一选择是保留bool
变量,该变量会在每次WaitOne()
和Set()
调用时发生变化,但我想知道该框架是否有更优雅的解决方案