Access is denied error in Windows Store App with MessageDialog

An efficient way to display one alert box or multiple without the Access is denied error in winjs.

A MessageDialog is fired asynchronously, so one needs to be cancelled before firing a second one.

I will actually split this in 2 ways. One way is for coding multiple MessageDialogs at once. The other way is for coding one MessageDialog that could be fired multiple times.

Multiple MessageDialogs in cascade:


var alertBoxOperation;
var alertBoxOperation2;

function fireAlert() {
    if (alertBoxOperation)
        alertBoxOperation.cancel();

    var alertBox = (new Windows.UI.Popups.MessageDialog("alert message",
        "title"));
    alertBoxOperation = alertBox.showAsync();

    alertBoxOperation.done(function () {

        var alertBox2 = (new Windows.UI.Popups.MessageDialog("second alert message",
                "title"));
        alertBoxOperation2 = alertBox2.showAsync();

    });

};

One MessageDialog fired multiple times:

var alertBoxOperation;

function fireMessageDialog() {

    if (alertBoxOperation)
        alertBoxOperation.cancel();

    var alertBox = (new Windows.UI.Popups.MessageDialog("alert message", "title"));
    alertBoxOperation = alertBox.showAsync();

};

setInterval(function(){ fireMessageDialog() },1000); //fire every second

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s