C# – Windows 10 UWP – stop background task if foreground app is running

background-taskcuwpwindowswindows-phone

How I can prevent background task from running if there are foreground app being executed? Using Universal Windows Platform for my app.

My background task is checking for new items on some site and sends a toast when there are new things available, but I wan't to prevent toast sending if user is running application right now.

I have tried to unregister task on my application launch and register it again when app is terminated, through, this is not fine solution for me — when device shuts down for some reason (for example, battery was removed) my task will be not registered until app launched again.

Thanks.

Best Answer

Use a named Mutex to synchronize between the foreground app and the background agent

Related Topic