EventWaitHandle发出信号原因

时间:2015-01-19 13:51:18

标签: c# multithreading .net-4.5 event-wait-handle

有没有办法确定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()调用时发生变化,但我想知道该框架是否有更优雅的解决方案

0 个答案:

没有答案