UWP App prevent suspension, serial port must stay active.

Joe 1 Reputation point

Developing an app that is pretty big now, and running into problems.
It is a UWP app that uses the serial port.
It specifically talks to a controller board hooked up to dangerous equipment.

It is very important this app doesn't suspend, but every time I minimize it lately (since a windows update) it suspends.

Customers report this also, and the only recourse is to tell them not to ever suspend the app and use another PC for any other needs.

Despite this instruction people still minimize the app, which could result in someone getting hurt.

How can the app suspension be prevented?

Universal Windows Platform (UWP)
{count} votes

3 answers

Sort by: Most helpful
  1. Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,861 Reputation points

    Welcome to Microsoft Q&A!

    but every time I minimize it lately (since a windows update) it suspends.

    It's by design, base on UWP life cycle, it will turn into suspend status when you minimize the app. However, you could postpone app suspension with extended execution.

    var newSession = new ExtendedExecutionSession();  
    newSession.Reason = ExtendedExecutionReason.Unspecified;  
    newSession.Revoked += SessionRevoked;  
    ExtendedExecutionResult result = await newSession.RequestExtensionAsync();  
    switch (result)  
        case ExtendedExecutionResult.Allowed:  
        case ExtendedExecutionResult.Denied:  

    Here is the detail official document that you could refer to.

    Thank you.

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. ArchieCoder 41 Reputation points

    Hi @Nico Zhu (Shanghai Wicresoft Co,.Ltd.) and @Roy Li - MSFT

    I have the issue. The situation is worse than it is.

    On Desktop PC
    Scenario 1: When I start the app, I call the RequestExtensionAsync, I get ExtendedExecutionResult.Allowed. If I minimize the app, the Suspend is called and the serial port is closed.
    Scenario 2: I debug the app and use the button "Suspend" in Lifecycle Events and then "Resume", Visual Studio freezes. I need to kill VS with Task Manager.
    Scenario 3: I moved the RequestExtensionAsync in Suspending event, I get denied result. I'm not surprised because the suspended action is in progress.

    Weird fact: I was able to see Scenario 1 working. I relaunched the app 3-4 times in a row and I was happy to see it working, but after these tries, I got back the bad behavior.

    On Surface Pro using the battery
    It does not work at all. I let the app ran for 1 hour so it can appear in Settings \ System \ Battery usage by App and then set always allow in the background, but it does nothing.

    This is also a crucial feature we need for our UWP app. I suspect a component broken in Windows.

    I'm running Windows 11 Pro - 22H2 - 22621.169

    Thank you

    0 comments No comments

  3. ArchieCoder 41 Reputation points

    I found the solution: when retrieving the session via ExtendedExecutionSession,RequestExtensionAsync(), we need to keep the session. You cannot call and forget.


    0 comments No comments