Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9172689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:24:35+00:00 2026-06-17T16:24:35+00:00

If you call the ShowAsync command on a MessageDialog object when another MessageDialog object

  • 0

If you call the ShowAsync command on a MessageDialog object when another MessageDialog object has already been displayed to the user but not dismissed (i.e. you show a popup when another one is already up), an UnauthorizedAccessException is thrown. This can make things difficult when you have multiple threads attempting to alert the user at the same time.

My current (stopgap) solution is merely to surround the ShowAsync call with a try/catch block and swallow the exception. This undesirably leads to the user missing out on subsequent notifications. The only other way around this that I can think of is to manually implement some sort of popup queue. This seems like an inordinate amount of work, however, considering other frameworks (like Windows Phone) do not have this issue and will merely display the popups one after another as the user dismisses them.

Is there another way to solve this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:24:37+00:00Added an answer on June 17, 2026 at 4:24 pm

    There are many ways to approach it and the choice might depend on your skills, requirements and preferences.

    My personal choice is to avoid using dialog boxes altogether since they are bad for user experience (evil). There are then alternative solutions like displaying a separate screen/page with the UI requiring user to provide some input when it really is required or displaying a non-modal popup somewhere on the side/edge/corner if the user input is optional and hiding it after a moment or some other sort of notification that doesn’t break user flow.

    If you disagree or don’t have the time, resources or skills to implement an alternative – you can create some sort of a wrapper around MessageDialog.ShowAsync() call to either queue or ignore new requests while a dialog is already shown.

    This class has extension methods to allow to either ignore a new show request when another dialog is already displayed or queue up the requests:

    /// <summary>
    /// MessageDialog extension methods
    /// </summary>
    public static class MessageDialogExtensions
    {
        private static TaskCompletionSource<MessageDialog> _currentDialogShowRequest;
    
        /// <summary>
        /// Begins an asynchronous operation showing a dialog.
        /// If another dialog is already shown using
        /// ShowAsyncQueue or ShowAsyncIfPossible method - it will wait
        /// for that previous dialog to be dismissed before showing the new one.
        /// </summary>
        /// <param name="dialog">The dialog.</param>
        /// <returns></returns>
        /// <exception cref="System.InvalidOperationException">This method can only be invoked from UI thread.</exception>
        public static async Task ShowAsyncQueue(this MessageDialog dialog)
        {
            if (!Window.Current.Dispatcher.HasThreadAccess)
            {
                throw new InvalidOperationException("This method can only be invoked from UI thread.");
            }
    
            while (_currentDialogShowRequest != null)
            {
                await _currentDialogShowRequest.Task;
            }
    
            var request = _currentDialogShowRequest = new TaskCompletionSource<MessageDialog>();
            await dialog.ShowAsync();
            _currentDialogShowRequest = null;
            request.SetResult(dialog);
        }
    
        /// <summary>
        /// Begins an asynchronous operation showing a dialog.
        /// If another dialog is already shown using
        /// ShowAsyncQueue or ShowAsyncIfPossible method - it will wait
        /// return immediately and the new dialog won't be displayed.
        /// </summary>
        /// <param name="dialog">The dialog.</param>
        /// <returns></returns>
        /// <exception cref="System.InvalidOperationException">This method can only be invoked from UI thread.</exception>
        public static async Task ShowAsyncIfPossible(this MessageDialog dialog)
        {
            if (!Window.Current.Dispatcher.HasThreadAccess)
            {
                throw new InvalidOperationException("This method can only be invoked from UI thread.");
            }
    
            while (_currentDialogShowRequest != null)
            {
                return;
            }
    
            var request = _currentDialogShowRequest = new TaskCompletionSource<MessageDialog>();
            await dialog.ShowAsync();
            _currentDialogShowRequest = null;
            request.SetResult(dialog);
        }
    }
    

    Test

    // This should obviously be displayed
    var dialog = new MessageDialog("await ShowAsync", "Dialog 1");
    await dialog.ShowAsync();
    
    // This should be displayed because we awaited the previous request to return
    dialog = new MessageDialog("await ShowAsync", "Dialog 2");
    await dialog.ShowAsync(); 
    
    // All other requests below are invoked without awaiting
    // the preceding ones to complete (dialogs being closed)
    
    // This will show because there is no dialog shown at this time
    dialog = new MessageDialog("ShowAsyncIfPossible", "Dialog 3");
    dialog.ShowAsyncIfPossible();
    
    // This will not show because there is a dialog shown at this time
    dialog = new MessageDialog("ShowAsyncIfPossible", "Dialog 4");
    dialog.ShowAsyncIfPossible();
    
    // This will show after Dialog 3 is dismissed
    dialog = new MessageDialog("ShowAsyncQueue", "Dialog 5");
    dialog.ShowAsyncQueue();
    
    // This will not show because there is a dialog shown at this time (Dialog 3)
    dialog = new MessageDialog("ShowAsyncIfPossible", "Dialog 6");
    dialog.ShowAsyncIfPossible();
    
    // This will show after Dialog 5 is dismissed
    dialog = new MessageDialog("ShowAsyncQueue", "Dialog 7");
    dialog.ShowAsyncQueue();
    
    // This will show after Dialog 7 is dismissed
    dialog = new MessageDialog("ShowAsyncQueue", "Dialog 8");
    dialog.ShowAsyncQueue();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Call me stupid but this thing has been eating away my productive time like
I call the following function with a mouseover event but it's not working. My
I call this a flash meeting, but maybe there is another more appropriate name.
I call service method using ThreadPool.QueueUserWorkItem(o => service.Method(arg1, arg2)); Service has object 'loggingService' with
Visual studio is giving me all sorts of warnings about not awaiting my MessageDialog.ShowAsync()
I call from a spreadsheet module a function that does some processing in another
Users call a web service API in my PHP code but don't properly encode
Call me a 'n00b', but I am new to creating Script Controls. I want
Call me lame, but I'm tired of my subconscious C-x C-s nervous twitch. I
Call me crazy, but I'm the type of guy that likes constructors with parameters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.