I'm working on a UWP project and recently I've added an out of process background task to it. I register the task in the OnLaunched()
method in App.cs
in order the task to be run only once the app is launched. But there is a problem: I have to refresh my xaml view after the task is completed and I have absolutely no idea how to make it happen(if I move the registration of the task to the Main.xaml.cs
, it will be run every time the page is opened).
I'll be happy to get any kind of help from you.
Here is my StartBackgroundTask()
method which I call in the OnLaunched()
method:
private async void StartBackgroundTask()
{
var task = BackgroundTaskRegistration.AllTasks.Values.FirstOrDefault(x => x.Name == "testTask");
if (task != null)
{
task.Unregister(true);
}
var taskBuilder = new BackgroundTaskBuilder();
taskBuilder.Name = "testTask";
taskBuilder.TaskEntryPoint = typeof(UpdateLocalDbBackgroundTask.UpdateLocalDbBackgroundTask).ToString();
ApplicationTrigger trigger = new ApplicationTrigger();
taskBuilder.SetTrigger(trigger);
taskBuilder.AddCondition(new SystemCondition(SystemConditionType.InternetAvailable));
task = taskBuilder.Register();
await trigger.RequestAsync();
}