I have an UWP app that is dependant on a background task. This task should thus be running all the time when the user is using the device. I have tried registering it with these triggers:
ApplicationTrigger _AppTrigger = new ApplicationTrigger(); builderInApp.SetTrigger(_AppTrigger); builderSession.SetTrigger(new SystemTrigger(SystemTriggerType.SessionConnected, false)); builderPower.SetTrigger(new SystemTrigger(SystemTriggerType.PowerStateChange, false));
But it seems like sometimes the task does not start. It starts 90% of the time after a restart or shutdown, continues 100% of the time after energy-saving mode, works 100% of the time if the system is just idle, about 50% after a Hybernation and only rarely if I do Energy Saver and then hybernate without unlocking.
Is there something I can do to make this more reliable? I have already added
<rescap:Capability Name="extendedBackgroundTaskTime"/> and enabled user management by User instead of windows.
Should I add some more triggers? Which ones? Is there another way to get better reliability? I don't mind using a .Net component if that would help, but my background task does have to be UWP.
Other question I have about this:
If I have triggered the background with trigger a, and trigger a fires again, does the process launch a second time, get cancelled and relaunched, or nothing happens?
Same question if I have triggered the background with trigger a, and trigger b fires, does the process launch a second time, get cancelled and relaunched, or nothing happens?