禁用Windows窗体上的所有活动窗体、Windows

2023-09-03 05:20:06 作者:一起来看流星雨

有没有什么办法可以暂时禁用的Windows窗体的所有事件?

Is there any way to temporarily disable ALL events on an windows form?

我在这里处理的辅助线程被破坏的主线程上的事件的情况。 (主线程事件正在修改的控件的数据绑定到所使用的辅助线程变量的内容。)寻找一种方法来锁定的形式,直到在辅助线程结束的处理。 (显然,移动处理主线程会做到这一点 - 但它也将冻结的用户界面,这不是我想要的任一)

I have situation where processing on a secondary thread is being corrupted by events on the main thread. (The main thread events are modifying the contents of controls that are data-bound to variables used by the secondary thread.) Looking for a way to "lock" the form until the processing on the secondary thread finishes. (Obviously, moving processing to the main thread would do this--but it would also "freeze" the UI, which isn't what I want either.)

推荐答案

感谢所有为你出色的帮助。真的帮了决策过程。 Upvotes给大家。使用锁结束了。 (即是,如果在每个事件处理程序的开始语句检查锁定状态,然后继续。)繁琐,不是所有的冷在技术上,而是简单,它的工作。

Thanks all for your excellent assistance. Really helped the decision making process. Upvotes to everyone. Ended up using a lock. (I.e. an if statement at the start of each event handler checks the lock status before continuing.) Tedious and not all that "cool" technically, but simple and it worked.