Debugging background tasks

It seems to me that my background task is not working / starting. Is there a way to debug them or test using an integration test.

This is an example of a 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(); } } } 

Registering a background task: (This code is run, verified using the 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 application manifest, I defined a new BackgroundTask with System Event and the following entry point: MyNamespace.MyBackgroundTask

Note: The background task is in another assembly as an application (Back-end / front-end division)

+7
source share
2 answers

This is a problem with the project. This article shows how to resolve the link.

+2
source

All Articles