windows phone 8.1 应用中的特定时间后台任务触发

Background task trigger on a specific time of day in windows phone 8.1 app

我正在开发一个 windows phone 8.1 WinRT c#/Xaml 应用程序,它需要每天早上下载一些 json 字符串。

如何让我的后台任务在一天中的特定时间进入 运行。我应该使用什么触发器?

请有人指导我或指出一些教程。

谢谢

这就是我解决问题的方法。

public async static Task RegisterBackgroundAgentAsync(string time)
    {
        var Datetime = DateTime.ParseExact(time, "HHmm", new System.Globalization.CultureInfo("en-US"));
        var taskname = "BackgroundAgentTask";
        var builder = new BackgroundTaskBuilder();
        builder.Name = taskname;
        builder.TaskEntryPoint = "BackgroundAgent.BackgroundAgentTask";
        TimeSpan ts = Datetime - DateTime.ParseExact(DateTime.Now.Hour.ToString("00") + DateTime.Now.Minute.ToString("00"), "HHmm", new CultureInfo("en-US"));
        if (ts.TotalMinutes < 15)
        {
           if (ts.TotalMinutes < 0)
           {
               if (1440 + ts.TotalMinutes > 15)
                  builder.SetTrigger(new TimeTrigger((uint)(1440 + ts.TotalMinutes), false));
               else
                  builder.SetTrigger(new TimeTrigger(15, false));
           }
           else
           {
               if (ts.TotalMinutes == 0)
                   builder.SetTrigger(new TimeTrigger(1440, false));
               else
                   builder.SetTrigger(new TimeTrigger(15, false));
           }
        }
        else
            builder.SetTrigger(new TimeTrigger((uint)ts.TotalMinutes, false));
        BackgroundTaskRegistration result;  
        var bas = (await BackgroundExecutionManager.RequestAccessAsync());
        if (bas == BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity)
            result = builder.Register();
    }