ManualResetEvent / WaitOne [英] ManualResetEvent / WaitOne

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

问题描述




我从Shell线程中使用ManuelResetEvent时遇到问题,同时从Shell接收

事件(新文件夹,重命名等)。


这就是我的工作:


从壳牌接收活动。

运行一些代码 - 设置ManauelResetEvent.Reset()。

代码继续 - 以及我测试句柄的其他地方

" ManuelResetEvent.WaitOne(100,true)" - 仍然在GUI线程中。

在等待(在WaitOne中)时,应用程序从壳牌中接收另一个来自

的事件 - 也在主线程中。


如何在阻止GUI线程的同时接收第二个事件

??


提前谢谢

BR

彼得

Hi,

I have a problem using a ManuelResetEvent in the GUI thread while receiving
events from the Shell (new folders, rename etc).

This is what i do:

Receiving an event from the Shell.
Running some code - setting ManauelResetEvent.Reset().
The code continue - and somewhere else i test the handle
"ManuelResetEvent.WaitOne(100, true)" - still in the GUI thread.
While waiting (in WaitOne), the application receive yet another event from
the Shell - also in the main thread.

How is it possible to receive the second event while blocking the GUI thread
??

Thank you in advance
BR
Peter

推荐答案

嗨彼得,


很抱歉延迟回复。


您能告诉我更多关于您的情况的信息吗?您是否正在关注

文件系统更改?优选地,简单但完整且可重现的
项目将非常适合快速排除故障。谢谢。

问候,

Walter Wang(wa****@online.microsoft.com,删除''在线。'')

Microsoft在线社区支持


================================= =================

在回复帖子时,请回复群组通过你的新闻阅读器

其他人可以从你的问题中学习并从中受益。

==================== ==============================

此帖子提供按现状 ;没有保证,也没有赋予任何权利。

Hi Peter,

Sorry for delayed reply.

Could you please tell me more about your scenario? Are you watching for
file system changes? Preferrably a simple but complete and reproducible
project will be great for quick troubleshooting. Thanks.
Regards,
Walter Wang (wa****@online.microsoft.com, remove ''online.'')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.


嗨Walter,


我会尝试创建一个小的几天内的演示项目!!


/ Peter
Hi Walter,

I will try to create a small demo project within a few days !!

/Peter


首先 - 我不太了解shell消息在

问题中,所以这只涵盖了一般主体...


我认为部分问题是阻塞UI线程永远不会是

好​​主意。


是否可以简单地禁用UI(即在一些策略上设置.Enabled =

false控制器),等待池线程,

然后回调(Control.Invoke)到UI线程上唤醒所有

备份并重新启用UI?


或者,Application.DoEvents()存在,这应该允许它处理足够的消息队列以获取外部消息 -

但是你无法预测它会发出什么信息g要处理好这个。如果可能的话,我倾向于使用第一种方法。


Marc
First - I don''t know a great deal about the shell messages in
question, so this only covers general principal...

I think part of the problem is that blocking the UI thread is never a
good idea.

Would it be possible to simply disable the UI (i.e. set .Enabled =
false on a few strategic controls), do the waiting on a pool thread,
and then call-back (Control.Invoke) onto the UI thread to wake it all
back up and re-enable the UI?

Alternatively, Application.DoEvents() exists, which should allow it to
process enough of the message-queue to get your external messages -
but you can''t really predict what messages it is going to handle doing
this. I would tend to use the first approach if possible.

Marc


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

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