0

i am writing a shared App which is shared with Windows Phone and metro . and i need to call my UI thread from the Worker thread in the Code behind of XAML in Metro App . And yeah i know that i can get it done by using async and await . But i cant use that because this thing will not be supported for other platforms (Android and Phone).

In Windows Phone i know that this can be done using Deployment.Dispatcher.Current.BeginInvoke(). But i cant get how it is done in a Metro App

Also , I am a newbie in C# and App development . So if you can present it in detail, It will be helpful .

1 Answers1

0

In the near future, I expect we will be able to use async on Portable Class Libraries for Android/WP/Windows Store. async works best if you treat the background operations as "services" for the UI, not the UI as a "service" for the background operations. So your code will work better if you restructure it by breaking up your big background operation into smaller chunks and have the UI side drive them, updating in-between each chunk. When your code is structured that way, your background operations will not ever need to marshal to the UI.

If you just want to get something working now with less work, you can use SynchronizationContext. When your background operation starts, capture SynchronizationContext.Current and later use the Send or Post methods to run UI updates from your background operation. This results in a messier design but it is something that will work today across Android/WP/Windows Store.

Stephen Cleary
  • 437,863
  • 77
  • 675
  • 810