C# 条件事件等待/手动重置事件

C# 条件事件等待/手动重置事件,c#,multithreading,events,synchronization,manualresetevent,C#,Multithreading,Events,Synchronization,Manualresetevent,我知道如何使用ManualResetEvent或synchronization原语(如Monitor)来等待事件和/或锁定,但我想知道是否有一种方法可以实现以下内容: ManualResetEvent resetEvent; public string WaitForOneThousandMs() { resetEvent.Wait(1000); if (WaitTime(resetEvent) <= 1000) return "Event occur

我知道如何使用ManualResetEvent或synchronization原语(如Monitor)来等待事件和/或锁定,但我想知道是否有一种方法可以实现以下内容:

ManualResetEvent resetEvent; 

public string WaitForOneThousandMs()
{
    resetEvent.Wait(1000);

    if (WaitTime(resetEvent) <= 1000)
        return "Event occured within 1000ms."; 
    else
        return "Event did not occur within 1000ms."; 
}
手动复位事件复位事件;
公共字符串WaitForOneThousandMs()
{
resetEvent.Wait(1000);

如果(WaitTime(resetEvent)看起来您在追求:

return resetEvent.WaitOne(1000) ? "Event occurred within 1000ms"
                                : "Event did not occur within 1000ms";
从以下文件:

返回值
如果当前实例接收到信号,则为true;否则为false


以类似的方式返回
bool

快速跟进问题:如果在WaitOne()方法开始等待之前在ManualResetEvent上调用Set()方法,WaitOne()方法会立即返回true吗?