c# - BackgroundTask UWP Windows 10 TimeTriggeredTask 示例已注册但从未启动

标签 c# windows-10 uwp

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

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 是否有效?

最佳答案

在我的例子中,我在 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));

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

关于c# - BackgroundTask UWP Windows 10 TimeTriggeredTask 示例已注册但从未启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31807296/

相关文章:

c# - 使用 wshttpbinding 和用户名身份验证保护服务时,WCF 服务显示异常

windows - 如何使用 `nasm` 和 `alink` 的组合链接 kernel32.lib 和 user32.lib ?

Vim 撕裂 tmux Pane 的显示

windows-store-apps - 从 Windows 应用商店下载并安装后 UWP 崩溃

c# - 从 .NET 发布到 REST 网络服务?

c# - 即时插入/编辑

c# - WPF DispatcherFrame 魔术 - 这是如何以及为什么起作用的?

c# - 如何将 Onedrive<Item> 的内容写入本地文件

windows - 通用 Windows 平台应用程序注册失败 - 被 AppLocker 阻止

c# - 相当于 x :Type in UWP