2
votes

I am trying to figure out how a UWP app can keep its data updated without having to be in foreground at all times.

For example, imagine an UWP app that is getting its data from somewhere. That data may change meaning that the UWP app will have to refresh it. I would like to have some kind of component doing that refreshing in background regardless whether UWP app is in foreground or not (whether user is staring at it or not).

In Android, you can use non-sticky-service or pending intent for this.

On IOS, I heard you can use something called BackgroundAppRefresh.

I did some research on UWP side and I am looking at AppService and I see it can be run out-of-app process or in-app process.

However, an in-app process Windows 10 AppService will be killed if app is back-grounded (user is not staring at it). And an out-of-app process Windows 10 AppService will run up to 30sec and then be killed https://docs.microsoft.com/en-us/windows/uwp/launch-resume/how-to-create-and-consume-an-app-service.

This means that my background syncing will not work since it will be stopped after maximum of 30 seconds if user is not having the UWP app in foreground (user is looking at it).

So, I concluded that Windows 10 AppService is not what I can use to implement this functionality.

How and what I can use to implement something like this in UWP?

2

2 Answers

1
votes

In UWP apps you can use BackgroundTasks to keep your app data refreshed even when the app is not actively running in the foreground.

https://docs.microsoft.com/en-us/windows/uwp/launch-resume/support-your-app-with-background-tasks

1
votes

It isn't possible. Also your information regarding iOS isn't correct - you don't have unlimited time to refresh your app there. It is only possible on Android as it is fully open even to the extent that you may make a device unusable with your app.

There is no guaranteed way to do this on UWP. BackgroundTask offers only limited time to work in background which isn't fit for you. However you may use some sort of the background download APIs that don't have restrictions if your problem is in the time to download the content. If you need the time to do something else then the best solution is to ask for ExtendedExecution when the app is in the foreground so that it doesn't go into the background, but it may not be granted and is not granted to run forever in the foreground either.

Also of note, if you expect the app to run on the PCs the app is not in the background unless it is minimized.