In my UWP project l'm using in process background task. The task runs every 15 min by timer trigger in different cases:
Case1: when application is running - in this case all works fine as expect.
Case2: when application closed - nothing happened as long as application still closed.
Please help me with this problem?
Code: //Here is my BackgroundTask.Run method
var deferral = taskInstance.GetDeferral();
if (!IsApplicationClosed)
{
//When application is running
await Dispatcher.RunAsync(WCoreDispatcherPriority.Normal, () => {
UpdateUI();
});
}
else
{
UpdateDataStorage();
}
deferral.Complete();
//Here is my OnBackgroundActivated method
base.OnBackgroundActivated(args);
var deferral = args.TaskInstance.GetDeferral();
switch (args.TaskInstance.Task.Name)
{
case "MyBackgroundTask":
{
var task = new MyBackgroundTask();
task.Run(args.TaskInstance);
} break;
};
deferral.Complete();
Thanks.