[WinUI 3] In-Process Background Task?

Brian 1 Reputation point
2022-01-02T08:11:44.33+00:00

I have a small, simple UWP app that I want to port to WinUI on Desktop. Everything went swimmingly except I can't get in-process background tasks working.

Two problems stand out:

  • Microsoft.UI.Xaml.Application does not implement OnBackgroundActivated()
  • BackgroundTaskBuilder.Register() throws System.Runtime.InteropServices.COMException: 'The request is not supported. (0x80070032)'

Are in-process background tasks supported or planned in WinUI on Desktop? Am I just missing something?

Advice, documentation, or an issue to follow are all appreciated.

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
783 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,907 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Andrew Leader-MSFT 206 Reputation points Microsoft Employee
    2022-01-05T18:45:09.577+00:00

    In-process background tasks for desktop apps need to use the COM background tasks: https://video2.skills-academy.com/windows/uwp/launch-resume/create-and-register-a-winmain-background-task

    However, if you're writing a C# app, the docs and samples don't work for .NET 5 and have to be updated, and our team is currently investigating how to use in-process COM background tasks from a C# .NET 5 WinUI 3 app.

    Out-of-process background tasks using the classic packaging project and a separate WinRT Component Library project should work, but as you mention it is additional complexity.

    1 person found this answer helpful.

  2. Ken Tucker 5,851 Reputation points
    2022-01-02T10:46:08.77+00:00

    The last comment in this issue should help

    https://github.com/microsoft/microsoft-ui-xaml/issues/4200


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.