I'm using Dispatcher.RunAsync() to show a MessageDialog from a background thread. But I'm having trouble figuring out how to get a result returned.
My code:
bool response = false;
await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
async () =>
{
DebugWriteln("Showing confirmation dialog: '" + s + "'.");
MessageDialog dialog = new MessageDialog(s);
dialog.Commands.Add(new UICommand(GetLanguageString("Util_DialogButtonYes"), new UICommandInvokedHandler((command) => {
DebugWriteln("User clicked 'Yes' in confirmation dialog");
response = true;
})));
dialog.Commands.Add(new UICommand(GetLanguageString("Util_DialogButtonNo"), new UICommandInvokedHandler((command) =>
{
DebugWriteln("User clicked 'No' in confirmatoin dialog");
response = false;
})));
dialog.CancelCommandIndex = 1;
await dialog.ShowAsync();
});
//response is always False
DebugWriteln(response);
Is there anyway to do it like this? I thought about maybe returning the value from inside RunAsync() but function is void.