在不运行应用程序的情况下注册后台任务 [英] Register a Background Task without running the app

查看:33
本文介绍了在不运行应用程序的情况下注册后台任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

tl;dr:如何在无需运行应用程序的情况下注册后台任务?

长版:

我想注册一个后台任务,以便在用户每次使用 SystemTriggerType.UserPresent 登录时运行.

我找到了有关注册任务的信息,但这是必须执行的代码.如果任务只需要在应用程序运行后 执行,那就没问题了.但是如何在运行应用程序的情况下注册任务?后台任务可以通过

注册

var builder = new BackgroundTaskBuilder();

然后

builder.Name = taskName;builder.TaskEntryPoint = taskEntryPoint;builder.SetTrigger(触发器);BackgroundTaskRegistration task = builder.Register();

正如这里提到的:

 <扩展><扩展类别="windows.preInstalledConfigTask" EntryPoint="PreInstallTask​​.Task"/></扩展>

您将在 清单架构 中找到扩展定义一个>

tl;dr: How do I register a Background Task without having to run the app?

Long version:

I want to register a Background Task to run every time the user logs in using SystemTriggerType.UserPresent .

I've found information about registering the Task, but that is code that has to be executed. That would be fine if the Task only has to be executed after the app runs. But how do I register the Task without running the app? A Background Task can be registered by

var builder = new BackgroundTaskBuilder();

and then

builder.Name = taskName;
builder.TaskEntryPoint = taskEntryPoint;
builder.SetTrigger(trigger);
BackgroundTaskRegistration task = builder.Register();

As mentioned here: Register a background task .

But as I said - my question is how to run this code before the app has ever been executed.

解决方案

You can use the preInstalledConfigTask extension in your manifest. This task will be started after your application is installed.

Sometimes your application will need to update immediately after being installed. This contract will enable you to immediately launch an update task without any user interaction to make sure your application is updated immediately.

Here is the full list of all the available extensions.

The preInstalledConfigtask can be set using the manifest editor:

 <Extensions>
    <Extension Category="windows.preInstalledConfigTask" EntryPoint="PreInstallTask.Task" />
  </Extensions>

You will find the extension definition in the manifest schema

这篇关于在不运行应用程序的情况下注册后台任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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