开发者

AutoResetEvent object , waits 60 secs OR event

开发者 https://www.devze.com 2022-12-19 19:55 出处:网络
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

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 .


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消