0

有什么方法可以确定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()我想知道框架是否有更优雅的解决方案

4

0 回答 0