簡體   English   中英

Windows應用商店8.1-未觸發后台任務

[英]Windows store app 8.1 - Background Task not triggered

我是Windows Store App的新手,我正在嘗試使用后台任務。

我以這種方式在按鈕單擊事件上注冊它:var builder = new BackgroundTaskBuilder();

         builder.Name = "bikePositionUpdate";
         builder.TaskEntryPoint = "BackgroundTaskGps.BikeGPSPositionUpdateBackgroundTask";
         builder.SetTrigger(new TimeTrigger(15, false)); // 

         BackgroundTaskRegistration taskRegistration = builder.Register();

因此,它應該在15'內發射。

這是我的任務:

namespace BackgroundTaskGps
{
    public sealed class BikeGPSPositionUpdateBackgroundTask : IBackgroundTask
    {
        public void Run(IBackgroundTaskInstance taskInstance)
        {
             Debug.WriteLine("run run run");
        }
    }
} 

這是我的清單

...
      <Extensions>
        <Extension Category="windows.backgroundTasks" EntryPoint="BackgroundTaskGps.BikeGPSPositionUpdateBackgroundTask">
          <BackgroundTasks>
            <Task Type="timer" />
          </BackgroundTasks>
        </Extension>
      </Extensions>
...

但是運行方法永遠不會受到打擊。

請問我可能是什么問題?

PS:我正在本地計算機(同一台開發PC)上測試我的應用程序。

請考慮我不是在談論Windows Phone App,而是Windows App

對於Windows Phone,您必須調用此

await BackgroundExecutionManager.RequestAccessAsync();

所以完整的代碼是

await BackgroundExecutionManager.RequestAccessAsync();
 builder.Name = "bikePositionUpdate";
         builder.TaskEntryPoint = "BackgroundTaskGps.BikeGPSPositionUpdateBackgroundTask";
         builder.SetTrigger(new TimeTrigger(15, false)); //For Windows Phone 8.1 minimum is 15 minutes

         BackgroundTaskRegistration taskRegistration = builder.Register();

您正在使用TimeTrigger Task來響應Trigger(fire)。 TimeTrigger Task之間的最短時間必須為30分鍾。 因此,您可以每30分鍾執行一次后台任務。 它類似於Windows 8中的周期觸發器。因此,更新后的代碼行將為:

builder.SetTrigger(new TimeTrigger(30, false));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM