使线程安全调用Windows窗体控件窗体、线程、控件、安全

2023-09-04 00:35:37 作者:金钱打造实力狗!

MSDN文章:如何:使线程安全的调用到Windows窗体控件 说,我们应该使用异步委托来拨打电话。但为什么异步委托拨打电话安全吗?

The MSDN article: How to: Make Thread-Safe Calls to Windows Forms Controls says we should use async delegate to make the call. But why does the async delegate make the call safe?

推荐答案

Windows控件使用组件对象模型(COM)单线程单元(STA)模式,因为这些基本控件是单元线程。此外,许多控制用于许多操作消息泵。该模型认为,所有的函数调用每个控件必须在创建控件在同一个线程。调用(而BeginInvoke和EndInvoke)老帅方法调用适当的线程。的

这是比尔·瓦格纳的更有效的C#。项目16.理解跨线程调用Windows窗体和WPF

From Bill Wagner's More Effective C#. Item 16. Understand Cross-Thread Calls in Windows Forms and WPF