2012-05-11 22 views
1

主應用程序如何從主應用程序啓動時已經運行的後臺任務獲取進度通知? 我註冊了一個由SystemTriggerType.TimeZoneChange觸發的後臺任務(爲簡單起見)。代碼如下:已經運行的BackgroundTask的進度更新?

public sealed class Class1:IBackgroundTask 
{ 
    public async void Run(IBackgroundTaskInstance taskInstance) 
    { 
     var defferal = taskInstance.GetDeferral(); 
     await Task.Delay(3000); 
     for (uint i = 1; i < 100; i++) 
     { 
      await Task.Delay(1000); 
      taskInstance.Progress = i; 
     } 
     defferal.Complete(); 
    } 
} 

進度條在進度條中正確報告。 在應用的開始我重新武官的完成和進度事件

foreach (var i in BackgroundTaskRegistration.AllTasks) 
{ 
    i.Value.Completed += task_Completed; 
    i.Value.Progress += task_Progress; 
} 

,但我想沒有更新的TaskInstance如果任務已經運行...

有什麼建議?

回答