Il me semble que ma tâche d'arrière-plan ne fonctionne pas/déclenche. Est-il possible que je peux les déboguer, ou le tester avec un test d'intégration.Débogage des tâches d'arrière-plan
Ceci est une tâche de fond exemple:
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();
}
}
}
Enregistrement de la tâche de fond: (Ce code est exécuté, vérifié avec le débogueur)
var backgroundTaskBuilder = new BackgroundTaskBuilder
{
TaskEntryPoint =
"MyNamespace.MyBackgroundTask",
Name = "MyBackgroundTask"
};
backgroundTaskBuilder.SetTrigger(new MaintenanceTrigger(15, false));
backgroundTaskBuilder.AddCondition(new SystemCondition(SystemConditionType.InternetAvailable));
backgroundTaskBuilder.Register();
Dans l'application manifeste que je l'ai défini une nouvelle BackgroundTask
avec un System Event
et le point d'entrée suivant: MyNamespace.MyBackgroundTask
Note: La tâche de fond est dans un autre assemblage que l'application (Back-end/séparation frontal)