在不运行应用程序的情况下注册后台任务

编程入门 行业动态 更新时间:2024-10-28 08:15:40
本文介绍了在不运行应用程序的情况下注册后台任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-28 09:39:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1171564.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   后台   情况下

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!