什么是射击的副作用UI线程的PropertyChanged不是? [英] What are the side effects of firing PropertyChanged not in UI thread?

查看:86
本文介绍了什么是射击的副作用UI线程的PropertyChanged不是?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您实现INotifyPropertyChanged,你可以提高事件非UI线程 - 我应该避免这种情况,为什么

If you implement INotifyPropertyChanged, you could raise event in non-UI thread - should i avoid this and why?

更新:这是一个关于在WPF应用程序绑定

Update: It is about binding in wpf application.

推荐答案

不,你不应该避免这种情况。 WPF乘警的PropertyChanged 活动来代表你的UI线程,但即使没有,很可能不是组件的责任这样做。

No you should not avoid this. WPF marshals PropertyChanged events to the UI thread on your behalf, but even if it did not, it is likely not the component's responsibility to do so.

更新:我稍微misinter preTED你的问题。出于某种原因,我还以为你具体是问不直接相关的UI背景组件。

UPDATE: I slightly misinterpreted your question. For some reason I thought you were asking specifically about background components not directly related to UI.

如果您的组件是用于直接消费的用户界面,那么它可能是有意义的变化元帅到UI线程,如Windows窗体。但是,如果该组件是UI不可知的,它没有一般意义,但如果需要的话,你可以通过使用当前在不可知的方式切换到UI线程的SynchronizationContext

If your component is intended for direct consumption by the UI, then it may make sense to marshal changes to the UI thread, such as with Windows Forms. However, if the component is UI agnostic, it does not generally make sense, although if necessary you can switch to the UI thread in an agnostic fashion by using the current SynchronizationContext.

我不编组的,需要与WPF的时候,因为正如我所说,通常你并不需要,因为WPF会为你。但是,如果你改变收藏过,那么你需要的,因为这样的变化不会自动整理。

I do marshalling as and when needed with WPF, because as I stated normally you don't need to since WPF does it for you. But if you're changing collections too then you will need to, since such changes are not automatically marshalled.

这篇关于什么是射击的副作用UI线程的PropertyChanged不是?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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