简体   繁体   English

适用于Windows的通用应用程序10.如何触发后台任务?

[英]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.

相关问题 通用Windows 10应用程序后台任务计时器以获取通知 - Universal Windows 10 app background task timer to get notifications 如何在Universal Windows 10应用中自定义文本框的边框和背景? - How to customize border and background of a textbox in a Universal Windows 10 app? 如何在Windows 8 JS Metro App中的后台任务中使用时间触发 - How to use Time Trigger in background task in Windows 8 JS Metro App win10通用应用程序后台任务未运行 - win10 universal app background task not running 如何在应用程序缩小或在后台运行时保持计时器运行(C#Windows 10通用应用程序) - How to keep a timer running when app is minised or in the background (C# Windows 10 universal app) 如何在Windows 10 Universal App中关闭splitView? - How to dismiss splitView in windows 10 universal app? 通用Windows应用程序后台任务“已退出,代码1(0x1)” - Universal Windows App Background Task “has exited with code 1 (0x1)” 如何从C ++后台任务(Windows Universal app)调用C#函数? - How to call C# function from C++ background task (Windows Universal app)? Windows 10通用音频后台播放器 - 无法注册后台任务:运行方法不触发 - Windows 10 Universal Audio Background Player - unable to register for background task: Run Method Doesn't fire Windows 10通用应用反馈 - Windows 10 Universal App Feedback
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM