.net3.0 中跨线程访问控件  
                                                                                     周银辉

这两天用WPF做一个项目的UI部分时, 发现跨线程地访问了UI控件, 自然地报异常了. 当时找了半天也没在控件中找到InvokeRequired属性和Invoke方法, 郁闷之极.....最后发现在.net3.0中,这有所改变了.

替代InvokeRequired的方法是DispatcherObject.CheckAccess()或DispatcherObject.VerifyAccess()方法,用于指示当前线程是否可以直接访问控件.

替代Invoke的方法是DispatcherObject.Dispatcher.BeginInvoke(...)方法

参考代码:

.net3.0 中跨线程访问控件// Uses the DispatcherObject.CheckAccess method to determine if 
.net3.0 中跨线程访问控件
// the calling thread has access to the thread the UI object is on
.net3.0 中跨线程访问控件
private void TryToUpdateButtonCheckAccess(object uiObject)

相关文章:

  • 2021-11-24
  • 2022-12-23
  • 2021-10-16
  • 2021-10-28
  • 2021-11-26
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-27
  • 2022-12-23
  • 2021-08-02
  • 2022-02-06
  • 2021-10-26
  • 2021-05-18
相关资源
相似解决方案