gpt4 book ai didi

.net - 检查AutoResetEvent状态

转载 作者:行者123 更新时间:2023-12-04 05:32:55 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com