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:
Use of App services for communicating with Win32 apps as pnp0a03 suggested.
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
Converting Datetime C# Type to Date JavaScript in ASP.NET MVC Razor Application
Returning a File to View/Download in ASP.NET MVC
How to Encrypt a Password Within Appsettings.Json for ASP.NET Core 2
C#, Access Child Properties from Parent Reference
Convert Json File to C# and Stored in Database
Generate Xml for <Govtalkmessage Xmlns="Http://Www.Govtalk.Gov.Uk/Cm/Envelope">
C# Adding Multiple Items to List
How to Get a Specific Column Value from a Datatable
Can Newtonsoft Json.Net Skip Serializing Empty Lists
Getting Value of Selected Item in List Box as String
Declare Properties to Ignore in Entities Interface (Ef Core)
How to Ignore First Two Columns of CSV File
Error Reading Jobject from Jsonreader. Current Jsonreader Item Is Not an Object: Startarray. Path
How to Convert English Digits to Arabic Digits
Convert from Httpresponsemessage to Iactionresult in .Net Core
Convert Character to Its Alphabet Integer Position
How to Rename Keys Within a Json File
How to Save Mailmessage Object to Disk as *.Eml or *.Msg File