Getting access to the UI dispatcher from a background thread (Win8/8.1)

I recently struggled quite a bit trying to get access to the UI dispatcher from a background thread. I had a scenario where when I receive a push notification, I had to update the XAML page UI. Obviously, I did not have access to the UI thread from the background thread so I binged quite a bit. Surprisingly, the documentation on this is not clear and I had to go through quite a bit of searching to find the right answer. Here it is for future reference:

await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High,
() =>
     // UI stuff here

Join the Conversation

1 Comment

Leave a comment

Your email address will not be published. Required fields are marked *