主线程忙时如何防止点击事件 [英] How Do I Prevent Click Events From Building Up Whilst Primary Thread Is Busy

查看:107
本文介绍了主线程忙时如何防止点击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下午全部,



我使用左手功能区控制我加载MDI儿童表格,我的问题是他们中的一些有一个对它们进行大量控制,因此在激活时需要几秒钟来重新启动线程。



我这里关注的是,如果我多次单击功能区按钮,它会导致HRESULT E_FAIL -2147467259返回错误代码,这很好,但是因为表单被加载,卸载和重新加载多次导致应用程序挂起。



当用户点击按钮我在处理时按钮被禁用,并在完成后再次重新启用,我的问题就在这里。如何在线程繁忙时让程序停止排队点击事件



因此我们知道我们无法在禁用时点击事件但是因为事件正在排队当线程被释放时,它会处理下一个被触发的事件 - 我希望完全阻止此区域的进一步点击,直到线程被释放。



有什么想法?

问候

Dev

Afternoon All,

I am using a left hand ribbon control i made to load up MDI Child Forms, the problem i have is that some of them have a significant amount of controls on them so takes a few seconds upon activation to relase the thread.

My concern here is that if i multiple click the ribbon button it results in a HRESULT E_FAIL -2147467259 error code being returned which is fine but then becuase the form is being loaded,unloaded and reloaded multiple times causing the application to hang.

When the user clicks the button i have the button disable while it processing and the re-enable again after it is finished, my question is here. how do i get the program to stop queueing click events whilst the thread is busy

so we know we cant click on things when disabled but becuase the event is being queued up and when the thread is released it then processes the next fired event - i want to completely prevent further clicks in this area until the thread is released.

Any thoughts?
Regards
Dev

推荐答案

你可以调用 Application.DoEvents [ ^ ]方法 - 启用控件。它应该消耗等待消息 - 即它们将触发但被忽略,因为控制被禁用。请注意该链接上的警告和建议。



你也可以考虑在另一个主题上完成这个过程--Sacha Barber在CodeProject上写了一系列文章这可能有所帮助 - 此链接适用于第一个初学者指南.NET中的线程化:n的第1部分 [ ^ ]
You could call the Application.DoEvents[^] method immediately prior to re-enabling the control. It should consume the waiting messages - i.e. they will fire but be ignored because the control is disabled. Please take note of the warnings and suggestions on that link.

You could also consider doing the process on another thread - Sacha Barber has written a series of articles here on CodeProject that might help - this link is for the first Beginners Guide to Threading in .NET: Part 1 of n[^]


这篇关于主线程忙时如何防止点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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