c# – 适用于Windows的通用应用程序10.如何触发后台任务?
我需要通过按动作按钮从交互式Toast通知触发后台任务.我不知道我做错了什么.我可以注册一个任务,并在visual studio中查看它.即使我可以调试它(debuger跳转到MyToastNotificationBackgroundTask.Run函数,但参数IBackgroundTaskInstance taskInstance是空对象),单击一个按钮永远不会运行任务或至少debuger dos不显示它.
我正在注册这样的后台任务 var builder = new BackgroundTaskBuilder(); builder.Name = "MyToastNotificationBackgroundTask"; builder.TaskEntryPoint = "Tasks.MyToastNotificationBackgroundTask"; builder.SetTrigger(new ToastNotificationActionTrigger()); BackgroundTaskRegistration task = builder.Register(); 显示通知 ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier(); ScheduledToastNotification myToastNotificaton = new ScheduledToastNotification(this.myToastXml,DateTime.Now.AddMinutes(1),TimeSpan.FromMinutes(60),2); myToastNotificaton .Id = "toast_54ahk36s"; toastNotifier.AddToSchedule(myToastNotificaton); 在app清单中 <Extensions> <Extension Category="windows.backgroundTasks" EntryPoint="Tasks.MyToastNotificationBackgroundTask"> <BackgroundTasks> <Task Type="systemEvent" /> </BackgroundTasks> </Extension> </Extensions> 在吐司模板xml动作按钮是 <actions> <input id="message" type="text" placeholderContent="200" /> <action activationType="background" content="Count" arguments="count" /> </actions> 后台任务itsetf namespace Tasks { public sealed class MyToastNotificationBackgroundTask : IBackgroundTask { public void Run(IBackgroundTaskInstance taskInstance) { var details = taskInstance.TriggerDetails as ToastNotificationActionTriggerDetail; ... } } } 我无法理解如何在通知模板操作按钮上指定activationype =“background”与MyToastNotificationBackgroundTask任务相关?我无法找到相关信息. 有人请分享你的知识.也许你有一个工作的例子或smf.任何帮助将不胜感激.提前致谢. 解决方法
后台任务(ToastNotificationActionTrigger)的触发器类型是将Toast操作连接到后台任务的内容.当用户点击操作时,app会查找具有ToastNotificationActionTrigger触发器的后台任务,并在找到时运行. 我使用你的代码,但无法重现问题,触发器工作正常.我的猜测是你已经注册了一个具有该名称但没有正确触发器类型的任务(先尝试取消注册) – 或者 – 你在toast xml(activationType字段)中有拼写问题. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |