EventWaitHandle [英] EventWaitHandle

查看:105
本文介绍了EventWaitHandle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想知道EventWaitHandle是否阻止其他事件的发生吗?

当我在主线程中调用eventWaitHandle.WaitOne()时,会发生我的问题,该语句会阻止主线程以及对我的第二个线程很重要的事件.我的第二个线程用于与控制器通信,并且始终处于while循环中以从控制器获取信息.我在此循环中的某个地方调用eventWaitHandle.Set().

我应该使用哪种方法?

谢谢您

Hi
I would like to know if EventWaitHandle blocks other events to happen?

My problem occurs when I call in main thread eventWaitHandle.WaitOne(), this statement blocks main thread and also events that are important for my second Thread. My second thread is for communicating with controller and is always in while loop to get information from controller. I call eventWaitHandle.Set() somewhere in this loop.

Wich method should i use?

THANK YOU

推荐答案

eventWaitHandle.WaitOne()将阻塞调用线程,直到发出事件信号为止.如果在同一线程上设置其他事件,则由于您的线程仍在WaitOne()中,因此不会收到信号.

使用System.Threading.EventWaitHandle.WaitAll在同一线程上等待多个事件
eventWaitHandle.WaitOne() will block the calling thread until the event is signalled. If you set other events on the same thread they will not get signalled due to your thread still being in WaitOne().

use System.Threading.EventWaitHandle.WaitAll to wait on multiple events on the same thread


这篇关于EventWaitHandle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆