How to Disable Uwp App Suspension

How to Disable UWP App Suspension?

ExtendedExecutionSession with ExtendedExecutionReason.Unspecified is a subject to multiple restrictions regarding resource consumption. Since your test device doesn't have a battery, then the most likely reason for your app getting suspended is its high memory use. You can try to optimize the app in terms of memory consumption and make use of Memory Management APIs as documentation suggests, but still this doesn't guarantee that your app will never get suspended.

If your app is aimed at business sector then you might consider using more powerful ExtendedExecutionForegroundSession instead of ExtendedExecutionSession. This would probably be the perfect solution for your problem. But it's a restricted capability, which means an app that utilizes it is not allowed to Windows Store - only to Windows Store for Business. You'd also need to manually declare the extendedExecutionUnconstrained capability in the manifest (see the Special and restricted capabilities section of documentation) to take advantage of the API.

Alternatively you can use hacks that prevent app from getting suspended for long periods of time:

  1. Use of App services for communicating with Win32 apps as pnp0a03 suggested.

  2. Use Background Media Playback for playing silent audio sample in the background infinitely in a loop (even if the user stops it manually or another app pauses it to play its own background audio, your app can trace it and automatically restart the playback).

How to stop UWP app close or termination on sleep or device lock?

UWP apps will suspend when they are in a non-use state such as in the background (or lock screen) for reasons of power-saving and system usage.

But for some applications that need to run continuously in the background, UWP provides extended execution to delay application suspension:

  • Postpone app suspension with extended execution

If your application is not going to be submitted to the Microsoft Store, then after Windows 10 1703, a restricted capability is provided: extendedExecutionUnconstrained.

After this capability is turned on, the application can continue to run when it is minimized.

<Package
...
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap mp rescap">
...
<Capabilities>
<rescap:Capability Name="extendedExecutionUnconstrained"/>
</Capabilities>
</Package>
  • Run in the background indefinitely

App or Code to Suspend Resume UWP app without Visual Studio

UWP provides dedicated APIs for suspending and resuming apps:
StartSuspendAsync
StartResumeAsync

Here is for example how you can suspend the FeedbackHub app:

var diag = await AppDiagnosticInfo.RequestInfoForPackageAsync("Microsoft.WindowsFeedbackHub_8wekyb3d8bbwe");
if (diag.Count > 0)
{
var resourceGroups = diag[0].GetResourceGroups();
if (resourceGroups.Count > 0)
{
await resourceGroups[0].StartSuspendAsync();
}
}

Note that you will need to declare the 'appDiagnostics' capability to call these APIs:

<Package
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap mp rescap">
...

<Capabilities>
<rescap:Capability Name="appDiagnostics" />
</Capabilities>
</Package>

extendedExecutionSession : Can we run UWP like Desktop app without Suspending?

Yes, you can do that with ExtendedExecution. One thing to note is when you run on battery (e.g. laptop, tablet) you will get suspended after some time - however you can prevent that as well by going into the Battery settings page and set your app as "Always Allowed".

Details are documented here: https://docs.microsoft.com/en-us/windows/uwp/launch-resume/run-minimized-with-extended-execution



Related Topics



Leave a reply



Submit