Correct Way to Get the Coredispatcher in a Windows Store App

Correct way to get the CoreDispatcher in a Windows Store app

This is the preferred way:

Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
() =>
{
// Your UI update code goes here!
});

The advantage this has is that it gets the main CoreApplicationView and so is always available. More details here.

There are two alternatives which you could use.

First alternative

Windows.ApplicationModel.Core.CoreApplication.GetCurrentView().CoreWindow.Dispatcher

This gets the active view for the app, but this will give you null, if no views has been activated. More details here.

Second alternative

Window.Current.Dispatcher

This solution will not work when it's called from another thread as it returns null instead of the UI Dispatcher. More details here.

Is CoreDispatcher the WinRT equivalent to WPF Dispatcher in win8 app store apps?

Here's what I've done:

public Screen(IPreConfigurationService preConfigurationService, INavigationService navigationService)
{
_preConfigurationService = preConfigurationService;
_navigationService = navigationService;
if (!IsInDesignMode)
_currentDispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
}

public string UserMessage
{
get { return _userMessage; }
set
{
_userMessage = value;
SafelyRaisePropertyChanged("UserMessage");
}
}
protected void SafelyRaisePropertyChanged(string message)
{
if (!IsInDesignMode)
_currentDispatcher.RunAsync(CoreDispatcherPriority.Normal, () => RaisePropertyChanged(message));
}
protected void ExecuteOnDispatcher(Action action)
{
_currentDispatcher.RunAsync(CoreDispatcherPriority.Normal, action.Invoke);
}

protected void SendUserMessage(string message)
{
UserMessage = message;
_currentDispatcher.RunAsync(CoreDispatcherPriority.Normal, () => AlertOnError(message));
}

How can i update the UI of my Windows universal app from a seperate thread?

await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
CoreDispatcherPriority.Normal,
() => { // your code should be here});

Correct way to get the CoreDispatcher in a Windows Store app

The application called an interface that was marshalled for a different thread - Windows Store App

This solved my issue:

Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
() =>
{
// Your UI update code goes here!
}
);

Correct way to get the CoreDispatcher in a Windows Store app

How do I interact with SQL in a Windows Store App

You can accomplish it with C# or JavaScript and you'd do it pretty much the same way, via services. Windows Store (C#/VB) applications don't have the same capabilities as desktop apps do to access databases via interfaces like ODBC, JDBC, SQL Native Client, etc., so you won't be connecting your Win RT app with SQL, you'll be connecting it via a hosted service that itself directly accesses the database.

Depending on how your LOB web application is partitioned, you may be able to expose existing functionality as a service layer and then invoke those services from your Windows Store app via HTTP requests. The HttpClient sample should help and depending on the service implementation you can also use WCF client capabilities in Windows Store apps.



Related Topics



Leave a reply



Submit