1
votes

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
idownvotedbecau.se/nomcve .. Please add related code on how you are registering/de-registering the background task..Also,please go through docs.microsoft.com/en-us/windows/uwp/launch-resume/… .. - Pratyay
I'm using a In-proc background task. The ref you provided is out of proc background task. But diff b/w these is only the process wise, but the background task as such behaves in same way and performs similar traits. Correct me if I'm wrong. How to add attachment here to submit the code? - SiD
I have removed my downvote as this seems to be a valid question. For adding code you can simply edit your question and paste it there, and format it with the code formatter present in the text toolbox. - Pratyay
Also how often do you need to make the API call ? if it is every 10-15mins or so, I would recommend going for the out of process execution as store apps are have some restrictions when suspended. - Pratyay
As per our requirements it should be any value in a range of (10sec - 1 min). So does out of proc background task runs indefinitely with application trigger instead of 10min restriction? Could you elaborate on what are the restrictions for store apps when suspended? - SiD

1 Answers

1
votes

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

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