I have some WP7 code that looks like this:
using System.Windows;
using System.Windows.Threading;
public static class GlobalDispatcher
{
public static Dispatcher Current { get { return Deployment.Current.Dispatcher; } }
}
What is the equivalent in WinRT? Is there no globally accessible Dispatcher (or CoreDispatcher) object?
You will want to use Window.Current.Dispatcher
.
Just adding this as answer, as it better solves the problem in my opinion:
Window.Current is null if the application is not focused and thus will bring you in trouble when there is a user involved ;)
CoreApplication.MainView.CoreWindow.Dispatcher isn't null...
– Jeremy White Aug 4 '13 at 13:09
try this:
var dispatcher = CoreApplication.MainView.CoreWindow.Dispatcher;
await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
try
{
//Your code here
}
catch (Exception ex)
{
HandleException(ex);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With