AutoResetEvent 对象,等待 60 秒或事件
我使用 AutoResetEvent 对象阻止线程 60 秒,但我想阻止它 60 秒或 AutoResetEvent.set() 事件
代码:
global:
private readonly AutoResetEvent _signal = new AutoResetEvent(false);
blocking:
_signal.WaitOne(60000, true);
event to give signal
_signal.Set();
但它总是等待整个 60 秒!即使我释放了信号。
Im using AutoResetEvent object to block a thread for 60 secs ,, but I would like to block it for 60 secs or AutoResetEvent.set() event
CODE :
global:
private readonly AutoResetEvent _signal = new AutoResetEvent(false);
blocking:
_signal.WaitOne(60000, true);
event to give signal
_signal.Set();
but it alwayas waits the whole 60 secs ! even if i released the signal .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
WaitOne()
调用会阻塞,因此您的Set()
调用只会在WaitOne()
超时后触发。为了减少等待时间,您需要从与等待线程不同的线程调用Set()
。不完全清楚你想做什么。
The
WaitOne()
call blocks so yourSet()
call will only fire after the timeout ofWaitOne()
. In order to wait less time you need to callSet()
from a different thread than the one waiting.Not entirely clear what you are trying to do.