It seems to me, that my background task is not working / triggering. Is there any way i can debug them, or test it with an integration test.
This is an example background task:
public sealed class MyBackgroundTask : IBackgroundTask
{
private ITileService _tileService;
//Tried a parameter-less constructor in case IoC doesn't work
public MyBackgroundTask() : this(new TileService) {}
public MyBackgroundTask(ITileService tileService)
{
_tileService = tileservice;
}
public async void Run(IBackgroundTaskInstance taskInstance)
{
Debug.WriteLine("MyBackgroundTask is running " + taskInstance.Task.Name );
taskInstance.Canceled += TaskInstanceOnCanceled;
if (!_cancelRequest && SomeOtherCondition)
{
var deferral = taskInstance.GetDeferral();
await _tileService.UpdateLiveTile(null);
deferral.Complete();
}
}
}
Registration of background task : (This code runs, checked with debugger)
var backgroundTaskBuilder = new BackgroundTaskBuilder
{
TaskEntryPoint =
"MyNamespace.MyBackgroundTask",
Name = "MyBackgroundTask"
};
backgroundTaskBuilder.SetTrigger(new MaintenanceTrigger(15, false));
backgroundTaskBuilder.AddCondition(new SystemCondition(SystemConditionType.InternetAvailable));
backgroundTaskBuilder.Register();
In the app manifest I have defined a new BackgroundTask
with a System Event
and the following entry point: MyNamespace.MyBackgroundTask
Note: The background task is in a different assembly as the app (Back-end / front-end separation)