Silverlight中的this.Dispatcher.BeginInvoke()和Deployment.Current.Dispatcher.BeginInvoke()方法之间的区别

wiz*_*rdz 7 silverlight mvvm silverlight-4.0

我知道Dispatcher.BeginInvoke()用于在UI线程中执行一些代码.最后我注意到有另一种方法可以通过使用'Deployment'类来获取Dispatcher实例.我想知道

调用this.Dispatcher.BeginInvoke()Deployment.Current.Dispatcher.BeginInvoke()函数之间是否有任何差异?

我什么时候应该使用this.Dispatcher.BeginInvoke()Deployment.Current.Dispatcher.BeginInvoke()

谢谢Alex

Gon*_*ing 11

简短回答:它们在Silverlight中是相同的,因此请使用较短的一个(如果在代码的上下文中可用).

this.Dispatcher.BeginInvoke() 确保它在正在运行的控件运行的线程上运行.

Deployment.Current.Dispatcher.BeginInvoke() 确保它在主UI线程上运行.

Silverlight中的两个总是相同的(在WPF中通常是相同的,除非您创建了额外的UI线程).

使用this.Dispatcher.BeginInvoke()除非你目前的情况下没有调度员,然后用全球性的,而不是.