Register a Background Task without running the app

2019-05-15 13:10发布

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.

2条回答
够拽才男人
2楼-- · 2019-05-15 13:46

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.

查看更多
再贱就再见
3楼-- · 2019-05-15 13:47

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:

preinstall task in editor

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

You will find the extension definition in the manifest schema

查看更多
登录 后发表回答