简体   繁体   中英

What is the use of Deployment.Current.Dispatcher.BeginInvoke( ()=> {…} )?

我在一些代码中看到过这种Deployment.Current.Dispatcher.BeginInvoke(()=> {...})格式。它曾经在后台做过一些工作吗?它的一般用途是什么?

No, it's not to do work in a background thread - it's to do work on the UI thread. So it's normally called from a background thread, in order to manipulate the UI, which can only be done on the UI thread.

The body of the lambda expression is the code which you want to execute in the UI thread.

When code that updates the UI executes from a thread other than the UI thread, an invalid cross-thread access exception occurs.

The dispatcher allows you to pass some code over to the UI thread from another thread.

The project I put in this post demonstrates this, among other concepts.

WebClient, HttpWebRequest and the UI Thread on Windows Phone 7

you'll need to use Deployment.Current. Dispatcher in a SilverLight application when you find yourself doing work in a non UI worker thread (within a context that does not inherit from DependencyObject) and you need to update the UI.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM