【发布时间】:2015-11-20 20:20:38
【问题描述】:
我需要通过按下操作按钮从交互式 toast 通知触发后台任务。我不知道我做错了什么。我能够注册一个任务并在视觉工作室中看到它。即使我可以调试它(调试器跳转到 MyToastNotificationBackgroundTask.Run 函数,但参数 IBackgroundTaskInstance taskInstance 是空对象),单击按钮永远不会运行任务,或者至少调试器不显示它。
我正在注册这样的后台任务
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);
在应用清单中
<Extensions>
<Extension Category="windows.backgroundTasks" EntryPoint="Tasks.MyToastNotificationBackgroundTask">
<BackgroundTasks>
<Task Type="systemEvent" />
</BackgroundTasks>
</Extension>
</Extensions>
在 toast 模板 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。任何帮助将不胜感激。提前致谢。
【问题讨论】:
标签: c# notifications win-universal-app background-task