首页 > 技术文章 > WPF 跨线程操作控件

sunlyk 2017-08-25 13:14 原文

跨线程操作UI
.NET2.0以来,就规定了不允许子线程对UI上创建的对象进行操作.
.在Winform中,通过控件的委托方法(Control.Invoke/ Control.BeginInvoke)进行调用.而在WPF中对控件增加了Dispathcer类.

Dispatcher
该类的常用方法为:
- Control.Dispathcher.CheckAccess(),用于检查是否允许访问.与Winform下的Control.InvokeRequired字段类似.
- Control.Dispathcher.BeginInvoke(),用于执行跨线程操作的委托方法.与Winform下的Control.BeginInvoke或Control.Invoke类似.

外部链接

推荐阅读