Register a Background Task without running the app

早过忘川 提交于 2019-12-07 19:18:27

问题


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.


回答1:


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




回答2:


I have had the same question lately and what is missing in previous answers is that the Pre-Installed Configuration only triggers for OEMs & MOs. See here.

That being said, it might be impossible to do what you want, as the task never triggers unless you are not managing the OS and shipping the image + having the necessary rights in your developer center. See here.



来源:https://stackoverflow.com/questions/40931552/register-a-background-task-without-running-the-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!