none
Keep PWA UWP connected when suspended

    Question

  • I created a UWP that just loads my site.

    It happens that on my site there is a setInterval (5 minutes) that sends a POST to a URL, indicating that the user is logged in. It turns out that the default behavior of a UWP is to suspend the app when it's being minimized, so my app does not send the POST after a while.

    I've read on several sites that I should use ExtendedExecutionSession Class to allow it to work minimized, however, all examples are in C#, my UWP does not have a line written in C# and I have no idea what I really should create and how to use it.

    What should I really do?

    I just want the application not to be suspended, just that, I do not have any background tasks or anything, because the site itself performs these tasks in the background.


    Monday, March 11, 2019 7:53 PM

All replies

  • Hi,

    ExtendedExecutionSession Class  is also available in JS code, you could call it in Javascript like in C#. If are making a PWA, you could refer this link:Get started with Progressive Web Apps. It shows how to create UWP apps using existing PWA or local hosted website.

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, March 12, 2019 5:56 AM
    Moderator
  • Where do I find JavaScript code examples?

    All the sites I searched for and in GitHub there are only examples in C

    Tuesday, March 12, 2019 12:44 PM
  • Hi Roy.

    How should I call the script?

    Should my complete JavaScript file be exactly like this?

    var newSession = new ExtendedExecutionSession();
    newSession.Reason = ExtendedExecutionReason.Unspecified;
    newSession.Revoked += SessionRevoked;
    ExtendedExecutionResult result = await newSession.RequestExtensionAsync();
    
    switch (result)
    {
        case ExtendedExecutionResult.Allowed:
            function doWork() {
                setInterval(function () {
                    fetch('https://example.com/', {
                        method: 'POST'
                    });
                }, 30000)
                close();
            }
    
            doWork();
            break;
    
        default:
        case ExtendedExecutionResult.Denied:
            break;
    }

    Should it be configured this way in Appxmanifest?

    <Extensions>
            <Extension Category="windows.backgroundTasks" StartPage="plugins/background.js">
              <BackgroundTasks>
                <Task Type="systemEvent" />
                <Task Type="pushNotification" />
                <uap:Task Type="chatMessageNotification" />
              </BackgroundTasks>
            </Extension>
          </Extensions>

    Wednesday, March 13, 2019 1:04 PM
  • Hi,

    Yes, try to put your request in the ExtendedExecutionSession. If this does not work, it will be impossible to do that in UWP apps.

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, March 14, 2019 6:05 AM
    Moderator
  • I tried, but nothing happens.
    To test I put a method that displays notifications every 10 seconds, but it did not work either.
    I have seen in C# samples that the request is done manually. How do I get this done automatically while minimizing?
    Thursday, March 14, 2019 11:55 AM