summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WinRT
diff options
context:
space:
mode:
authorPaul DiPietro <pauldipietro@users.noreply.github.com>2016-12-16 09:58:47 -0600
committerRui Marinho <me@ruimarinho.net>2016-12-16 15:58:47 +0000
commitdb4486db8f41642dcd2948c929bee54500d23938 (patch)
tree1ab1b646ce0804781f2d00bd124c294ca0dce8c6 /Xamarin.Forms.Platform.WinRT
parent3716c57aabc2407b02a8fd724d6ad9074e7b9d8f (diff)
downloadxamarin-forms-db4486db8f41642dcd2948c929bee54500d23938.tar.gz
xamarin-forms-db4486db8f41642dcd2948c929bee54500d23938.tar.bz2
xamarin-forms-db4486db8f41642dcd2948c929bee54500d23938.zip
[WinRT] Use a queue to prevent multiple MessageDialogs from causing a crash (#347)
* [WinRT] Use a queue to prevent multiple MessageDialogs from causing a crash * Make change to use Device.IsInvokeRequired
Diffstat (limited to 'Xamarin.Forms.Platform.WinRT')
-rw-r--r--Xamarin.Forms.Platform.WinRT/Platform.cs37
1 files changed, 35 insertions, 2 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/Platform.cs b/Xamarin.Forms.Platform.WinRT/Platform.cs
index d6a68fed..75dd772c 100644
--- a/Xamarin.Forms.Platform.WinRT/Platform.cs
+++ b/Xamarin.Forms.Platform.WinRT/Platform.cs
@@ -761,8 +761,41 @@ namespace Xamarin.Forms.Platform.WinRT
dialog.CancelCommandIndex = (uint)dialog.Commands.Count - 1;
}
- IUICommand command = await dialog.ShowAsync();
- options.SetResult(command.Label == options.Accept);
+ if (Device.IsInvokeRequired)
+ {
+ Device.BeginInvokeOnMainThread(async () =>
+ {
+ IUICommand command = await dialog.ShowAsyncQueue();
+ options.SetResult(command.Label == options.Accept);
+ });
+ }
+ else
+ {
+ IUICommand command = await dialog.ShowAsyncQueue();
+ options.SetResult(command.Label == options.Accept);
+ }
+ }
+ }
+
+ // refer to http://stackoverflow.com/questions/29209954/multiple-messagedialog-app-crash for why this is used
+ // in order to allow for multiple MessageDialogs, or a crash occurs otherwise
+ public static class MessageDialogExtensions
+ {
+ static TaskCompletionSource<MessageDialog> _currentDialogShowRequest;
+
+ public static async Task<IUICommand> ShowAsyncQueue(this MessageDialog dialog)
+ {
+ while (_currentDialogShowRequest != null)
+ {
+ await _currentDialogShowRequest.Task;
+ }
+
+ var request = _currentDialogShowRequest = new TaskCompletionSource<MessageDialog>();
+ var result = await dialog.ShowAsync();
+ _currentDialogShowRequest = null;
+ request.SetResult(dialog);
+
+ return result;
}
}
} \ No newline at end of file