从后台线程更新绑定属性 [英] Updating bound properties from a background thread

查看:152
本文介绍了从后台线程更新绑定属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WPF控件绑定到ViewModel中的属性。令我吃惊(因为这似乎不是WPF的广告功能),从后台线程更改绑定属性似乎没有问题。我的UI更新没有例外。为什么是这样?从后台线程更新绑定属性或任何其他限制是否有任何性能问题?

解决方案

WPF自动确保绑定在主线程上更新。



没有性能命中。如果在后台线程上执行属性更新更好。调度主线程的更新将增加在那里完成的工作量。您将更新View和ViewModel,而不仅仅是查看。通常情况下,差异可以忽略不计,但如果大量更新正在迅速发生,那么可能会导致用户界面的响应速度更快降低。


I have a WPF control that is bound to properties in my ViewModel. To my surprise (as this doesn't seem like a well-advertised feature of WPF), there seem to be no issues with changing the bound properties from a background thread. My UI updates with no exceptions. Why is this? Are there any performance issues with updating a bound property from a background thread, or any other limitations?

解决方案

WPF automatically ensures that bindings are updated on the main thread.

There's no performance hit. If anything it's better to do the property updates on the background thread. Dispatching updates to the main thread would increase the amount of work being done there. You would be updating both the View and the ViewModel, rather than just the View. The difference should normally be negligible, but if a lot of updates are happening rapidly then it might cause the UI's responsiveness to degrade more quickly.

这篇关于从后台线程更新绑定属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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