0

for a LOB App written as a Windows Universal App, I want to register a Background Task when the app is installed without the need to start it. From what I can see, the documentation points me to the Pre-Installed Configuration capability in the Package.appxmanifest and I found this.

However, when using this extension, the background task is not registered nor can I see that it runs anything.

Here is my Pre-Installed Configuration extension in Package.appxmanifest:

<Extension Category="windows.preInstalledConfigTask" EntryPoint="Foo.BackgroundTasks.DefaultRegistrationBackgroundTask" />

To validate that the Task and Entrypoint is set correctly, I registered it using the Update Task capability, increased the App version, deployed it again and the background task is registered and everything works as expected.

Here is my Update Task extension in Package.appxmanifest:

 <Extension Category="windows.updateTask" EntryPoint="Foo.BackgroundTasks.DefaultRegistrationBackgroundTask" />

Is the Pre-Installed Configuration Task somehow limited or needs other configuration? How can I debug this sort of issue? No Breakpoints are hit.

Code of Foo.BackgroundTasks.DefaultRegistrationBackgroundTask:

public sealed class DefaultRegistrationBackgroundTask : IBackgroundTask
{
    private BackgroundTaskDeferral _backgroundTaskDeferral;
    public void Run(IBackgroundTaskInstance taskInstance)
    {

        // Deferral is required if code uses any async call
        _backgroundTaskDeferral = taskInstance.GetDeferral();

        // Location Services
        BackgroundTaskHelper.RegisterBackgroundTask("Foo.BackgroundTasks.LocationBackgroundTask",
            "Foo.LocationBackgroundTask",
            new SystemTrigger(SystemTriggerType.UserPresent, false),
            null);

        // Referal releases
        _backgroundTaskDeferral.Complete();
    }  
}
Sebastian Zolg
  • 1,921
  • 2
  • 14
  • 35

1 Answers1

1

PreinstalledConfigTask is limited to preinstalled apps, i.e. apps that come with the device from the OEM or Microsoft. It won't get triggered for apps that the user acquires from the Store (or via side-load).

Stefan Wick MSFT
  • 13,600
  • 1
  • 32
  • 51
  • Thanks! So there is no chance to register the background Task without the user starting the app ? we might have the chance to autostart the app on first login - would prelaunch be an option ? – Sebastian Zolg Aug 04 '17 at 14:50
  • Correct, there is no way to run app code without the app being launched at least once. The UpdateTask is an exception here. You are welcome to log a feature suggestion on UserVoice: https://wpdev.uservoice.com/forums/110705-universal-windows-platform – Stefan Wick MSFT Aug 04 '17 at 17:46
  • Such a feature would really enable new use cases. I will log it on UserVoice. Thanks. Assuming we have full control over the OS, as it is a managed client, do you see any other way? Autostart & Prelaunch for example? When the OS is deployed by us, is there a way register this App as an OEM App and use the mentioned task or how to get there ? – Sebastian Zolg Aug 05 '17 at 07:10
  • Prelaunch runs opportunistically (it's not guaranteed). If you own the box, the easiest path is probably to write a RunOnce key. – Stefan Wick MSFT Aug 05 '17 at 14:27