开发者

Difference between this.Dispatcher.BeginInvoke() and Deployment.Current.Dispatcher.BeginInvoke() methods in Silverlight

I know Dispatcher.BeginInvoke() is used to execute some 开发者_如何学JAVApiece of code in the UI thread.Recently I noticed that there is another way to get the Dispatcher instance by using 'Deployment' class. I would like to know

Is there any diffrence between the invokation of this.Dispatcher.BeginInvoke() and Deployment.Current.Dispatcher.BeginInvoke() functions ?, and

when should I use this.Dispatcher.BeginInvoke() and Deployment.Current.Dispatcher.BeginInvoke() ?

Thanks Alex


Short answer: They are the same in Silverlight, so use the shorter one (if available in the context of your code).

this.Dispatcher.BeginInvoke() ensures it is run on the thread that the control in question is running under.

Deployment.Current.Dispatcher.BeginInvoke() ensures it is run on the main UI thread.

The two are always the same in Silverlight (and usually the same in WPF, unless you have created extra UI threads).

Use this.Dispatcher.BeginInvoke() unless your current context does not have a dispatcher, then use the global one instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜