It is easier to directly get CoreWindow from a thread other than the UI. The following code will work everywhere, even if GetForCurrentThread() or Window.Current returns null.
CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, <lambda for your code which should run on the UI thread>);
eg:
CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { // Your UI update code goes here! });
You will need to reference the Windows.ApplicationModel.Core namespace:
using Windows.ApplicationModel.Core;
Cœur Jun 26 '13 at 8:32 2013-06-26 08:32
source share