时间触发器不触发后台任务 UWP [英] Timetrigger not firing backgroundtask UWP

查看:25
本文介绍了时间触发器不触发后台任务 UWP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我和这里的这个人有同样的问题:

有没有人可以解释为什么它不起作用.我使用的是 10.0.10586 版本

解决方案

  1. 您可以使用 powershell 确认您的任务是否已注册.使用管理权限打开 powershell,然后运行Get-AppBackgroundTask".列出了所有已注册的任务.如果您在列表中找不到您的任务,则说明注册时存在一些问题.

  2. 您是否将后台任务项目添加为对主应用程序的引用?

  3. 您是否调用了 BackgroundExecutionManager.RequestAccessAsync()?您应该在注册之前从 UI 线程调用它.

  1. 我在商店中有一个带有 timetrigger 的后台任务示例应用程序.它隐藏在店面和搜索中,但您可以从以下链接下载:

https://www.microsoft.com/store/p/ddlgbgtasktrial/9nblggh4s785

这个应用程序注册了一个简单的后台任务,间隔时间为 15 分钟.此任务只是将调试消息输出到日志文件.该应用程序显示日志.如果运行良好,您可以在大约 15 分钟的时间间隔内看到调试输出.

我已确认该应用适用于 Win10 桌面版 10586.494 和移动版 14393.0.

I have the same problem as this guy over here: UWP Timetrigger not working but I can't comment the question because my reputation is not high enough, so I'm creating a new question.

As I said, I have the same problem. I registered the background task, but nothing happens. My background task is located in a seperate project (Runtime Component). So that's not the problem. This is the method I made to register the task:

public static BackgroundTaskRegistration Register(string name, string taskEntryPoint, IBackgroundTrigger trigger, IBackgroundCondition condition)
    {
        var foundTask = BackgroundTaskRegistration.AllTasks.FirstOrDefault(x => x.Value.Name == name);
        if (foundTask.Value != null)
            return (BackgroundTaskRegistration)foundTask.Value;

        var builder = new BackgroundTaskBuilder();
        builder.Name = name;
        builder.TaskEntryPoint = taskEntryPoint;
        builder.SetTrigger(trigger);
        if (condition != null)
            builder.AddCondition(condition);

        return builder.Register();
    }

and this is how I call it:

BackgroundTaskRegister.Register(nameof(NotificationTask), $"Epguides.Background.{_backgroundTaskName}", new TimeTrigger(30, true), null);

When I debug my application and use Lifecycle Events in Visual studio to test my background task, everything works fine. So the problem is not the task.

When I inspect the BackgroundTaskRegistration result I see that the property trigger is null. on the MSDN page of BackgroundTaskRegistration.Trigger it says the following

This is not intended for use in your code. For all unsupported trigger types, the value returned by this property is null.

So from what I understand is that TimeTrigger is an unsupported trigger type, because Trigger is null.

This is what is declared in the manifest file

Is there someone that can explain why it is not working. I'm using version 10.0.10586

解决方案

  1. You can confirm that the your task is registered or not by using powershell. Open powershell with administrative rights, and run 'Get-AppBackgroundTask'. All of registered tasks are listed. If you can't find your task from the list, there are some problems at registration.

  2. Have you add the background task project as a reference to your main app?

  3. Have you call the BackgroundExecutionManager.RequestAccessAsync()? You should call it before registering, from UI thread.

  1. I have a sample app of background task with timetrigger on the store. It's hidden from storefront and search, but you can download it from following link:

https://www.microsoft.com/store/p/ddlgbgtasktrial/9nblggh4s785

This app regist a simple background task with 15min interval timetrigger. This task just output the debugmessage to the logfile. The app shows a log. If it works well, you can see the debug output with about 15min intervals.

I've confirmed that the app works with Win10 desktop 10586.494 and mobile 14393.0.

这篇关于时间触发器不触发后台任务 UWP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆