Exception while opening multiple MessageDialog. RRS feed

  • Question

  • Hi,

    In windowsRT facing some issue while opening multiple MessageDialog one after another. it throws AccessDenied Exception.

    I have searched in forum and also got some solution but they are not generic. 

    Can anyone provide me some MessageDialogHelper which can handle all the Dialog from through out the app.

    like : If any MessageDialog already available on UI thread then add upcoming Dialog to queue and open it once first one has been dismissed.



    Wednesday, March 26, 2014 11:40 AM


  • this what you looking for?

    protected async override void OnNavigatedTo(NavigationEventArgs e)
                var d1 = new MessageDialog("dialog1");
                var t1 = d1.OpenMessageDialogQueued();
                var d2 = new MessageDialog("dialog2");
                var t2 = d2.OpenMessageDialogQueued();
                var d3 = new MessageDialog("dialog3");
                var t3 = d3.OpenMessageDialogQueued();
                var d4 = new MessageDialog("dialog4");
                var t4 = d4.OpenMessageDialogQueued();
                await t1;
                await t2;
                await t3;
                await t4;
        public static class MessageDialogHelper
            private static bool handlingDialog = false;
            private readonly static Queue<QueuedDialog> _dialogs = new Queue<QueuedDialog>();
            public static Task<IUICommand> OpenMessageDialogQueued(this MessageDialog dialog)
                var queuedDialog = new QueuedDialog(dialog);
                if (!handlingDialog)
                return queuedDialog.CompletionSource.Task;
            private async static void ShowNextDialog()
                    handlingDialog = true;
                    while (_dialogs.Count > 0)
                        var dialog = _dialogs.Dequeue();
                        var nextDialog = await dialog.ShowAsync();
                    handlingDialog = false;
            private class QueuedDialog
                private MessageDialog dialog;
                public QueuedDialog(MessageDialog dialog)
                    this.dialog = dialog;
                    CompletionSource = new TaskCompletionSource<IUICommand>();
                public TaskCompletionSource<IUICommand> CompletionSource { get; private set; }
                public async Task<IUICommand> ShowAsync()
                    var result = await dialog.ShowAsync();
                    return result;

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    • Marked as answer by Anne Jing Friday, April 4, 2014 8:21 AM
    Wednesday, March 26, 2014 12:10 PM