4

我正在使用 Scenario4 测试背景示例,它从不调用 Run,我正在按照步骤操作,这就是我所看到的:

1.- 打电话后

BackgroundTaskRegistration task = builder.Register();

任务有 Trigger = null

是否应该是之前指定的触发器

builder.SetTrigger(trigger); ?

2.-理论上,当我注册一个后台任务时,它应该出现在这里 EventViewer - BackgroundTaskInfrastructure 但它没有,应该出现在这里吗?

3.-尝试调试我调试位置-暂停应用程序但超过15分钟后它从未到达,应该像暂停和等待一样简单吗?

我还在运行通知中添加了:

var toastXML = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
var toastTextElements = toastXML.GetElementsByTagName("text");
toastTextElements.First().AppendChild(toastXML.CreateTextNode("Hello World:"));
var toastNotification = new ToastNotification(toastXML);
toastNotification.ExpirationTime = DateTimeOffset.UtcNow.AddSeconds(30);
ToastNotificationManager.CreateToastNotifier().Show(toastNotification);

但它永远不会出现。那么带有 TimeTrigger 的 BackgroundTask 是否有效?

4

1 回答 1

4

就我而言,我在 BackgroundTask 的 Run 方法中有一个 await 调用。观看视频https://channel9.msdn.com/Events/Windows/Developers-Guide-to-Windows-10-RTM/Background-Execution后,我了解到我必须致电:

 var cost = BackgroundWorkCost.CurrentBackgroundWorkCost;

并得到

 var deferral = taskInstance.GetDeferral();

最后,当我的通话结束时,请致电:

 deferral.Complete();

现在它总是调用我的任务总是完成,唯一的问题,我认为这是不允许的,我不能调用:

  Launcher.LaunchUriAsync(new Uri(favorite.Uri, UriKind.Absolute));

可能是不允许启动器,但现在每 15 分钟显示一次吐司。

于 2015-08-27T06:28:21.417 回答