WPF 数据绑定线程安全? [英] WPF Databinding thread safety?

查看:25
本文介绍了WPF 数据绑定线程安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,假设我有一个数据绑定到的对象,它实现了 INotifyPropertyChanged 以在值发生更改时告诉 GUI...

Well lets say i have an object that i databind to, it implements INotifyPropertyChanged to tell the GUI when a value has changed...

如果我从与 GUI 线程不同的线程触发此操作,wpf 会如何表现?

if i trigger this from a different thread than the GUI thread how would wpf behave?

它会确保它从内存而不是 cpu 缓存中获取属性的值吗?

and will it make sure that it gets the value of the property from memory and not the cpu cache?

或多或少我在问 wpf 是否在包含该属性的对象上执行 lock()...

more or less im asking if wpf does lock() on the object containing the property...

推荐答案

INotifyPropertyChanged 触发的值更改会自动编组回调度程序.(http://blog.lab49.com/archives/1166)

Value changes fired by INotifyPropertyChanged are automatically marshalled back onto the dispatcher. (http://blog.lab49.com/archives/1166)

在您喜欢的任何线程上触发此事件...

Fire this event on any thread you like...

INotifyCollectionChanged 触发的值更改不能可靠地编组到调度程序上.(http://csharplive.wordpress.com/2008/09/11/wpf-data-binding-observablecollection-cross-thread-binding-support/)

Value changes fired by INotifyCollectionChanged are NOT reliably marshalled onto the dispatcher. (http://csharplive.wordpress.com/2008/09/11/wpf-data-binding-observablecollection-cross-thread-binding-support/)

如果您需要从其他线程更新可观察集合,请按照此链接中的建议进行操作

If you need to update an observable collection from a different thread, follow the advice in this link

这篇关于WPF 数据绑定线程安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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