关于AutoResetEvent的问题

//ManualResetEvent

AutoResetEvent a1 = new AutoResetEvent(false);

不传入false默认为true,不会阻塞线程,所以必须传false。

WaitOne(int); WaitOne(int,bool); WaitOne(timespan,bool); 

第二个参数传true代表超时后由set()设置不阻塞线程,如果传入false,如:WaitOne(2000,false);当超过两秒后线程就解除阻塞了,也就是等第二次在进入此线程时候会直接执行并不会阻塞线程。

WaitOne返回值为true代表当前线程不阻塞,返回为false代表当前线程被阻塞。

WaitOne第二个参数:如果等待之前先退出上下文的同步域(如果在同步上下文中),并在稍后重新获取它(需要其他地方调用Set方法),则为 true;否则为 false

参考链接:https://www.cnblogs.com/qiaqia-liu/p/6123646.html

https://www.cnblogs.com/lzjsky/archive/2011/07/11/2102794.html

https://blog.csdn.net/qq_16587307/article/details/104040338

https://docs.microsoft.com/zh-cn/dotnet/api/system.threading.waithandle.waitone?view=net-5.0

猜你喜欢

转载自blog.csdn.net/Liumotor/article/details/107085239