I have tried this code to make sure the task can only run once:
static bool running = false;
public void Run(IBackgroundTaskInstance taskInstance)
{
if (running)
{
makeToast("Cancelled because another already running");
return;
}
running = true;
// Do stuff.
}
But it seems like running stays true if even if all instances of a task are terminated. Setting it to false on cancelation also isn't reliable, as the cancelation method is not always called (unexpected system shutdown, crash...).
Is there a way to if other instances are running within the background task itself?