BackgroundTask UWP Windows 10 TimeTriggeredTask示例已注册但从未激活
我正在使用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);
但它永远不会出现。 BackgroundTask和TimeTrigger一起工作吗?
在我的例子中,我在BackgroundTask的Run方法中有一个等待调用。 观看video后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分钟显示一次。