2012-09-03 76 views
7

在我看来,我的后台任务不工作/触发。有没有什么办法可以调试它们,或者用集成测试来测试它。调试后台任务

这是一个例子后台任务:


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(); 
      } 
     } 
} 

的后台任务注册: (此代码运行时,与调试器选中)


var backgroundTaskBuilder = new BackgroundTaskBuilder 
               { 
                TaskEntryPoint = 
                 "MyNamespace.MyBackgroundTask", 
                Name = "MyBackgroundTask" 
               }; 

       backgroundTaskBuilder.SetTrigger(new MaintenanceTrigger(15, false)); 
       backgroundTaskBuilder.AddCondition(new SystemCondition(SystemConditionType.InternetAvailable)); 
       backgroundTaskBuilder.Register(); 

在应用清单我已经定义了一个新的BackgroundTaskSystem Event及以下切入点:MyNamespace.MyBackgroundTask

注: 后台任务是在不同的组件,作为应用(后端/前端分离)

回答