从后台线程更新绑定属性 [英] Updating bound properties from a background thread
问题描述
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屋!