locked
nested Windows.UI.Popups.MessageDialog.showAsync() causes access denied exception

    Question

  • Is this a bug, or am I doing it incorrectly?

    In my application, I need to display another message dialog if the user pressed a certain button on the previous dialog. However it doesn't work. It can be illustrated by the simple code below:

    app.onactivated = function (args) {
    
            var m = new Windows.UI.Popups.MessageDialog("Blah?");
            m.commands.append(new Windows.UI.Popups.UICommand("Blah!", function () {
                var m2 = new Windows.UI.Popups.MessageDialog("You blahed me back!");
                m2.showAsync();
            }));
            m.showAsync();
    }

    at the line "m2.showAsync();", VS throws the exception saying "Access is denied".

    Wednesday, September 12, 2012 4:02 PM

Answers

  • Hi

    This is a Async function, the second step it depend on first step, you need to .done() method.

    for example:

    function completedCallback_Click() {
            // Create the message dialog and set its content
            var msg = new Windows.UI.Popups.MessageDialog("New updates have been found for this program. Would you like to install the new updates?", "Updates available");
    
            // Add commands and set their CommandIds
            msg.commands.append(new Windows.UI.Popups.UICommand("Install updates", null, 1));
            msg.commands.append(new Windows.UI.Popups.UICommand("Don't install", null, 2));
    
            // Set the command that will be invoked by default
            msg.defaultCommandIndex = 2;
    
            // Show the message dialog
            msg.showAsync().done(function () {         
                    var msg1 = new Windows.UI.Popups.MessageDialog("Message1");
                    msg1.showAsync(); 
            });
        }

    For more please read:http://msdn.microsoft.com/en-us/library/windows/apps/Hh701079.aspx

    Hope it helpful.

    • Marked as answer by kayson Thursday, September 13, 2012 6:09 AM
    Thursday, September 13, 2012 3:06 AM

All replies

  • Hi

    This is a Async function, the second step it depend on first step, you need to .done() method.

    for example:

    function completedCallback_Click() {
            // Create the message dialog and set its content
            var msg = new Windows.UI.Popups.MessageDialog("New updates have been found for this program. Would you like to install the new updates?", "Updates available");
    
            // Add commands and set their CommandIds
            msg.commands.append(new Windows.UI.Popups.UICommand("Install updates", null, 1));
            msg.commands.append(new Windows.UI.Popups.UICommand("Don't install", null, 2));
    
            // Set the command that will be invoked by default
            msg.defaultCommandIndex = 2;
    
            // Show the message dialog
            msg.showAsync().done(function () {         
                    var msg1 = new Windows.UI.Popups.MessageDialog("Message1");
                    msg1.showAsync(); 
            });
        }

    For more please read:http://msdn.microsoft.com/en-us/library/windows/apps/Hh701079.aspx

    Hope it helpful.

    • Marked as answer by kayson Thursday, September 13, 2012 6:09 AM
    Thursday, September 13, 2012 3:06 AM
  • Thanks for posting the solution, Dino, this is really helpful.
    Tuesday, October 16, 2012 6:56 PM