Windows Store app. Performing one task at startup from a secondary tile.

I have a Windows Store app that creates extra tiles. When I clicked the tile, I want the application to execute, which is an effective, stand-alone function (that is, I do not want to return to the application, but I want the application to do something and then exit). Therefore, in this case, I want to start the mail client, for example. Here, where I am still:

app.addEventListener("activated", function (args) {
    if (args.detail.kind === activation.ActivationKind.launch) {

        if (args.detail.arguments !== "") {
            // Activation arguments are present that 
            // were declared when the secondary tile was pinned to Start.
            args.setPromise(WinJS.UI.processAll().done(function () {
                var emailaddress = args.detail.arguments;
                var promise = Email.SendNewMail.sendEmail(emailaddress);
                //promise.complete();
                return;
            }));

        } else if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
            // TODO: This application has been newly launched. Initialize
            // your application here.
        } else {
            // TODO: This application has been reactivated from suspension.
            // Restore application state here.
        }
...

Email function here:

    sendEmail: function sendEmail(addess, subject, body) {
        var mailto = new Windows.Foundation.Uri("mailto:?to=" + addess + "&subject=" + subject + "&body=" + body);
        return Windows.System.Launcher.launchUriAsync(mailto);
    }

The error that I am currently getting is "The object is disconnected from its client", which I believe is caused by the program exiting before the promise is completed. How can this behavior be achieved in WInRT?

UPDATE:

MS , , , 3.6.

+5
2

, :

- - Windows Store [sic] "".

: http://msdn.microsoft.com/en-us/library/windows/apps/hh465372.aspx

, , , . , ( Promise , then done) , , , .

, , , :

  • setTimeout - - 1
  • Windows.UI.Popups.MessageDialog

, window.close(); .

Eight.js : (, , , , ):

Eight.Message.confirmAsync("Send the email?", function (doSend) {
    if (!doSend) return;

    Email.SendNewEmail.sendEmail(emailaddress).done(function (e) {
        window.close();
    });
});

: , , , , . . - , . , , . , Windows Store Apps, Microsoft.

+2

, then() launchUriAsync() :

Email.SendNewMail.sendEmail(emailaddress).then(function (success) {
    if (success) {
        window.close()
    } else {
        // Display error message
    }
});
0

All Articles