Run Background Task Indefinitely in UWP

4.2k Views Asked by At

I have a requirement to constantly poll an API and provide notifications in UWP app irrespective of whether it is Visible to user OR minimized OR Not in focus OR Suspended.

If I choose to write it in the app itself, it stopped working while app is suspended and resumed while again app is opened or kept in focus. So I chosen Background Task so that it runs everytime even when app is suspended (ex: minimized).

But now any background task is limited to short span of 30secs and if it is triggered using Application Trigger it lasts max for 10min.

I tried re triggering the background task on completion of 10mins, but during the re trigger phase if app is minimized or device is locked it doesn't happen. Re trigger is happening only after I resume the app by which I'm loosing the indefinite behavior.

I also tried adding the restricted capability to run task indefinitely but this is not allowed for Store app and only for Side loading. But My requirement is to support this for Store app.

Kindly help me how to achieve this behavior using Background Task, or else any other model available in UWP platform to achieve this.

1

There are 1 best solutions below

16
On

To run background tasks for extended/indefinite periods of time you need to declare the extendedBackgroundTaskTime capability in your app's manifest.

https://learn.microsoft.com/en-us/windows/uwp/launch-resume/run-in-the-background-indefinetly