Mi sembra che il mio task in background non funzioni/si inneschi. C'è un modo in cui posso eseguire il debug di loro, o testarlo con un test di integrazione.Debug delle attività in background
Questo è un compito esempio di fondo:
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();
}
}
}
Registrazione dei task in background: (Questo codice viene eseguito, controllato con debugger)
var backgroundTaskBuilder = new BackgroundTaskBuilder
{
TaskEntryPoint =
"MyNamespace.MyBackgroundTask",
Name = "MyBackgroundTask"
};
backgroundTaskBuilder.SetTrigger(new MaintenanceTrigger(15, false));
backgroundTaskBuilder.AddCondition(new SystemCondition(SystemConditionType.InternetAvailable));
backgroundTaskBuilder.Register();
Nel file manifest ho definito un nuovo BackgroundTask
con un System Event
e il seguente punto di entrata: MyNamespace.MyBackgroundTask
Nota: Il compito sfondo è in un assembly diverso come il (separazione back-end/front-end) app