[英]Universal app for windows 10. how to trigger background task?
I need to trigger a background task from interactive toast notification by pressing action button. 我需要通过按动作按钮从交互式Toast通知触发后台任务。 i don't know what i'm doing wrong.
我不知道我做错了什么。 i'm able to register a task and see it in visual studio.
我可以注册一个任务,并在visual studio中查看它。 even i can debug it (debuger jumps to MyToastNotificationBackgroundTask.Run function but argument IBackgroundTaskInstance taskInstance is empty object), clicking on a button never runs the task or at least debuger dosn't show it.
即使我可以调试它(debuger跳转到MyToastNotificationBackgroundTask.Run函数,但参数IBackgroundTaskInstance taskInstance是空对象),单击一个按钮永远不会运行任务或至少debuger dos不显示它。
I'm registering a background task like this 我正在注册这样的后台任务
var builder = new BackgroundTaskBuilder();
builder.Name = "MyToastNotificationBackgroundTask";
builder.TaskEntryPoint = "Tasks.MyToastNotificationBackgroundTask";
builder.SetTrigger(new ToastNotificationActionTrigger());
BackgroundTaskRegistration task = builder.Register();
showing notification 显示通知
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);
in app manifest 在app清单中
<Extensions>
<Extension Category="windows.backgroundTasks" EntryPoint="Tasks.MyToastNotificationBackgroundTask">
<BackgroundTasks>
<Task Type="systemEvent" />
</BackgroundTasks>
</Extension>
</Extensions>
in toast template xml action buttons are 在吐司模板xml动作按钮是
<actions>
<input id="message" type="text" placeholderContent="200" />
<action activationType="background" content="Count" arguments="count" />
</actions>
background task itsetf 后台任务itsetf
namespace Tasks
{
public sealed class MyToastNotificationBackgroundTask : IBackgroundTask
{
public void Run(IBackgroundTaskInstance taskInstance)
{
var details = taskInstance.TriggerDetails as ToastNotificationActionTriggerDetail;
...
}
}
}
i can't understand how specifying activationype="background" on a notification templates action button is relating to MyToastNotificationBackgroundTask task? 我无法理解如何在通知模板操作按钮上指定activationype =“background”与MyToastNotificationBackgroundTask任务相关? i can't find relevant info on that.
我无法找到相关信息。
somebody please share your knowledge. 有人请分享你的知识。 maybe you have a working example or smf.
也许你有一个工作的例子或smf。 any help will be appreciated.
任何帮助将不胜感激。 thanks in advance.
提前致谢。
I can't understand how specifying activationype="background" on a notification templates action button is relating to MyToastNotificationBackgroundTask task?
我无法理解如何在通知模板操作按钮上指定activationype =“background”与MyToastNotificationBackgroundTask任务相关? i can't find relevant info on that.
我无法找到相关信息。
The trigger type of the background task (ToastNotificationActionTrigger) is what connects the Toast action to the background task. 后台任务(ToastNotificationActionTrigger)的触发器类型是将Toast操作连接到后台任务的内容。 When user taps the action, app looks for a background task with ToastNotificationActionTrigger trigger to and runs if it finds one.
当用户点击操作时,app会查找具有ToastNotificationActionTrigger触发器的后台任务,并在找到时运行。
I used your code but couldn't reproduce the problem, trigger works fine. 我使用你的代码,但无法重现问题,触发器工作正常。 My guess is that you have already registered a task with that name but without the correct trigger type (try unregister first) -or- you have a spelling issue in the toast xml (activationType field).
我的猜测是你已经注册了一个具有该名称但没有正确触发器类型的任务(先尝试取消注册) - 或者 - 你在toast xml(activationType字段)中有拼写问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.