Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Background task and running app detection

I have background task in my app, which runs every 15 minutes (when on lock screen). Is it possible to detect if my app is running when background task is executing ? I'd like to skip background task execution in such case, to avoid concurrency problems.

like image 710
Tadeusz Wójcik Avatar asked Oct 22 '22 03:10

Tadeusz Wójcik


2 Answers

You can't detect when your app is running from a background task but you can detect when the background task is running from your app with the BackgroundTaskRegistration Progress and Completed events.

This sample covers everything you should need. http://code.msdn.microsoft.com/windowsapps/Background-Task-Sample-9209ade9

like image 183
Tim Avatar answered Oct 23 '22 22:10

Tim


Because both the app and the background task have access to app data, have the app store a flag in ApplicationData.localSettings when it's activated, clearing the flag when it's suspended, and resetting the flag when it's resumed. The background task can then check that flag when it starts and make the decision from there.

like image 30
Kraig Brockschmidt - MSFT Avatar answered Oct 23 '22 21:10

Kraig Brockschmidt - MSFT