2012-09-03 109 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

注: 後臺任務是在不同的組件,作爲應用(後端/前端分離)

回答