Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows 10 UWP - stop background task if foreground app is running

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.

like image 643
Vladislav Vorobiev Avatar asked Sep 27 '15 07:09

Vladislav Vorobiev


1 Answers

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

like image 51
user5421274 Avatar answered Oct 20 '22 01:10

user5421274