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

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

问题描述

好吧,让我说我有一个对象,我可以绑定,它实现INotifyPropertyChanged告诉GUI,当一个值已经改变...



如果我触发这个与GUI线程不同的线程如何wpf的行为?



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

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

解决方案

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



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






INotifyCollectionChanged 不可靠地编组到调度程序。 ( http:// csharplive如果你需要的话,那么你可以使用这个方法来实现这个功能。从不同的线程更新可观察的集合,请遵循此链接中的建议


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

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

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

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

解决方案

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...


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天全站免登陆