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

查看:80
本文介绍了时间触发未触发后台任务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天全站免登陆