Run Background Task Indefinitely in UWP

ぐ巨炮叔叔 提交于 2020-01-03 05:04:08

问题


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:


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



来源:https://stackoverflow.com/questions/49857055/run-background-task-indefinitely-in-uwp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!