AutoResetEvent 对象,等待 60 秒或事件

发布于 2024-08-20 08:49:33 字数 300 浏览 2 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光匆匆的小流年 2024-08-27 08:49:33

WaitOne() 调用会阻塞,因此您的 Set() 调用只会在 WaitOne() 超时后触发。为了减少等待时间,您需要从与等待线程不同的线程调用 Set()

不完全清楚你想做什么。

The WaitOne() call blocks so your Set() call will only fire after the timeout of WaitOne(). In order to wait less time you need to call Set() from a different thread than the one waiting.

Not entirely clear what you are trying to do.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文