Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Disable UWP App Suspension?

Tags:

c#

uwp

I am using C# to develop a UWP app for Windows 10 running only on desktop computers, targeting platform version 10.0.14393.0. Due to business requirements, the app lifecycle must behave like a traditional Win32 application.

Therefore, I followed the recommendation from this article to request an ExtendedExecutionSession with ExtendedExecutionReason.Unspecified. I also configured Windows to never sleep and never hibernate.

Still, on rare occasions, Windows will revoke the extended execution session with reason SystemPolicy and then proceed to suspend the UWP app.

Two questions:

  1. How can I get more information (system logs? event logs?) regarding what led to Windows revoking the extended execution session?
  2. How can I get rid of these rare cases of suspensions so that the UWP app lifecycle behaves exactly like Win32 applications (that is, stay running until user explicitly stops it from running)?

Thanks!

like image 794
hwaien Avatar asked Nov 16 '17 21:11

hwaien


People also ask

How do I stop UWP from suspending apps?

Go to Start > Settings > Privacy > scroll down to Background apps > select the app in question & toggle "Off" to turn it off.

Why is UWP suspending processes?

The UWP process is suspended for a variety of reasons. When the user minimizes the application. When the system enters a low-power state.

How do I stop UWP from suspending Windows 11?

Launch Task Manager via Ctrl+Shift+Esc shortcut keys. Then select the suspended program and click End Task. This should stop the suspended process in Windows 11.

How do I Unsuspend an app from Task Manager?

Once it is in suspend state CPU cycles are not used. You can resume the process by right click on the same process and then clicking on Resume Process.

How do I remove UWP from Start menu?

Yes: In your manifest, go to the VisualElements element and add the attribute AppListEntry="none" . This removes the app from the Start menu, as well as from Search.

Is Microsoft abandoning UWP?

Microsoft continues to baby-step around the obvious, but it has officially deprecated the Universal Windows Platform (UWP) as it pushes the desktop-focused Windows App SDK (formerly called Project Reunion) and WinUI 3 as the future of Windows application development.


2 Answers

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).

like image 160
A. Milto Avatar answered Sep 19 '22 06:09

A. Milto


I was trying to solve this for days and days but then found this link. Very good explanation and solution to this and most importantly.. easy to understand. You need to put the code in the app.xaml.cs and also edit the package manifest file. You will also need the following directives in the app.xaml.cs

using Windows.ApplicationModel.ExtendedExecution.Foreground; using System.Threading.Tasks;

non-suspending-uwp

like image 38
maximdj Avatar answered Sep 20 '22 06:09

maximdj