I am making an application for a Windows 8.1 tablet and I am using the async keyword quite strongly. My understanding of the async keyword is that although it seems to be in sync with the programmer, there is no guarantee that you will work on the same thread when your wait is over.
In my code behind the file, I use the dispatcher to run any UI updates in the UI thread. Each example I found indicates that it is good practice to use a callback script, but I did not mention this when using async. In my understanding of async, it would seem that I would need to use the dispatcher whenever I want to update the interface after any waiting call.
I tried to be more clear by adding my understanding to the code below.
private void SomeEventHandler(object sender, RoutedEventArgs e)
{
UpdateUI();
await Foo();
UpdateUI();
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
UpdateUI();
});
}
I only need access to the UIContext, and the thread doesn't matter? It would be great if someone could clarify this to me.
source
share