Skip to content

Commit bfb237c

Browse files
committed
Update bg task builder topics
1 parent 4efe052 commit bfb237c

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

hub/apps/windows-app-sdk/applifecycle/background-tasks.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Using background tasks in Windows apps
3-
description: This article provides an overview of using background tasks and describes how to create a new background task in a WinUI app with the Windows App SDK BackgroundTaskBuilder APIs.
4-
ms.date: 02/26/2025
3+
description: Get an overview of using background tasks and learn how to create a new background task in an app with the BackgroundTaskBuilder in Windows App SDK.
4+
ms.date: 03/19/2025
55
ms.topic: concept-article
66
keywords: windows 11, winui, background task, app lifecycle, windows app sdk
77
ms.localizationpriority: medium
@@ -16,7 +16,7 @@ This article provides an overview of using background tasks and describes how to
1616

1717
Background tasks are app components that run in the background without a user interface. They can perform actions such as downloading files, syncing data, sending notifications, or updating tiles. They can be triggered by various events, such as time, system changes, user actions, or push notifications. These tasks can get executed when corresponding trigger occurs even when the app is not in running state.
1818

19-
The Windows Runtime (WinRT) [BackgroundTaskBuilder](/uwp/api/windows.applicationmodel.background.backgroundtaskbuilder) was designed for UWP applications, and many of the background task triggers are not supported for full trust COM Components. They are supported only when registered with WinRT components that are launched with a `backgroundtaskhost` process. Due to this, Windows App SDK desktop applications can't directly register the full trust COM components to be launched with background task triggers. They require a workaround of including the WinRT components in the project. The Windows App SDK API avoids this workaround so WinUI and other desktop applications that use Windows App SDK can register the full trust COM components directly with background tasks.
19+
The Windows Runtime (WinRT) [BackgroundTaskBuilder](/uwp/api/windows.applicationmodel.background.backgroundtaskbuilder) was designed for UWP applications, and many of the background task triggers are not supported for full trust COM Components. They are supported only when registered with WinRT components that are launched with a `backgroundtaskhost` process. Due to this, Windows App SDK desktop applications can't directly register the full trust COM components to be launched with background task triggers. They require a workaround of including the WinRT components in the project. The [BackgroundTaskBuilder](/windows/windows-app-sdk/api/winrt/microsoft.windows.applicationmodel.background.backgroundtaskbuilder) in Windows App SDK API avoids this workaround so WinUI 3 and other desktop applications that use Windows App SDK can register the full trust COM components directly with background tasks.
2020

2121
## Register a background task
2222

@@ -58,6 +58,8 @@ The corresponding package manifest entry for the background task is as follows:
5858
</Extension>
5959
```
6060

61+
A full WinUI 3 background task registration sample can be found on [GitHub](https://github.com/microsoft/WindowsAppSDK-Samples/tree/release/experimental/Samples/BackgroundTask).
62+
6163
## Related content
6264

6365
- [Guidelines for background tasks in UWP apps](/windows/uwp/launch-resume/guidelines-for-background-tasks)

hub/apps/windows-app-sdk/migrate-to-windows-app-sdk/guides/background-task-migration-strategy.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,42 @@
11
---
22
title: Background task migration strategy
3-
description: Considerations and strategies for approaching the migration process, and how to migrate your UWP background tasks to use the Windows App SDK background task APIs.
3+
description: Considerations for approaching the migration process and how to migrate your UWP background tasks to use the Windows App SDK BackgroundTaskBuilder.
44
ms.topic: concept-article
5-
ms.date: 02/26/2025
5+
ms.date: 03/19/2025
66
keywords: Windows, App, SDK, migrate, migrating, migration, port, porting
77
ms.localizationpriority: medium
88
# customer intent: As a Windows developer, I want to learn about the considerations and strategies for migrating my UWP background tasks to use the Windows App SDK background task APIs.
99
---
1010

1111
# Background task migration strategy
1212

13-
Background tasks are used heavily in UWP apps for performing jobs when a particular trigger is invoked on the machine. As these don’t require any service to be running listening for the triggers, it's very power efficient. So, while migrating UWP apps to WinUI and other desktop apps that use Windows App SDK, developers may require support for implementing background tasks on the platform.
13+
Background tasks are used heavily in UWP apps for performing jobs when a particular trigger is invoked on the machine. As these don’t require any service to be running listening for the triggers, it's very power efficient. So, while migrating UWP apps to WinUI 3 and other desktop apps that use Windows App SDK, developers may require support for implementing background tasks on the platform.
1414

15-
Background tasks offered in the UWP app model can either be out-of-proc or in-proc. Below is the migration strategy for each of these types when moving to the Windows App SDK [BackgroundTaskBuilder](/windows/windows-app-sdk/api/winrt/microsoft.windows.applicationmodel.background.backgroundtaskbuilder) APIs.
15+
Background tasks offered in the UWP app model can either be out-of-proc or in-proc. This article describes the migration strategy for each of these types when moving to [BackgroundTaskBuilder](/windows/windows-app-sdk/api/winrt/microsoft.windows.applicationmodel.background.backgroundtaskbuilder) APIs in Windows App SDK.
1616

1717
## Out-of-proc background tasks
1818

1919
In the case of out-of-proc background tasks in UWP, background tasks will be written as a Windows Runtime (WinRT) component, and the component is set as the [TaskEntryPoint](/uwp/api/windows.applicationmodel.background.backgroundtaskbuilder.taskentrypoint) on [BackgroundTaskBuilder](/uwp/api/windows.applicationmodel.background.backgroundtaskbuilder) during registration. While migrating to Windows App SDK, developers can keep this as-is and package the WinRT component together with the desktop project. In this case, the broker infrastructure will be launching `backgroundtaskhost` process when the trigger is invoked, and the WinRT component background task would be executed in the process. In this approach, the background task would be running in a Low Integrity Level (IL) process (`backgroundtaskhost.exe`) while the main desktop project would be running in a Medium IL process.
2020

21-
If the application needs to to run a background task in a medium IL process itself, then full trust COM component needs to be used for background task. In that scenario, developers must go with [BackgroundTaskBuilder](/windows/windows-app-sdk/api/winrt/microsoft.windows.applicationmodel.background.backgroundtaskbuilder) API for successful registration of the full trust COM component. Note that the [BackgroundTaskBuilder](/uwp/api/windows.applicationmodel.background.backgroundtaskbuilder) API from the **Windows.ApplicationModel.Background** namespace will throw exceptions while registering of some of the triggers.
21+
If the application needs to to run a background task in a medium IL process itself, the full trust COM component needs to be used for background tasks. In that scenario, developers must use the Windows App SDK [BackgroundTaskBuilder](/windows/windows-app-sdk/api/winrt/microsoft.windows.applicationmodel.background.backgroundtaskbuilder) to register the full trust COM component. Note that the [BackgroundTaskBuilder](/uwp/api/windows.applicationmodel.background.backgroundtaskbuilder) API from the **Windows.ApplicationModel.Background** namespace will throw exceptions while registering of some of the triggers.
2222

23-
A background task registration sample can be found [here](https://github.com/microsoft/WindowsAppSDK-Samples/tree/release/experimental/Samples/BackgroundTask).
23+
A full WinUI 3 background task registration sample can be found on [GitHub](https://github.com/microsoft/WindowsAppSDK-Samples/tree/release/experimental/Samples/BackgroundTask).
2424

2525
More details on the implementation are available [here](/windows/uwp/launch-resume/create-and-register-a-winmain-background-task). The only required change would be to replace the WinRT [BackgroundTaskBuilder](/uwp/api/windows.applicationmodel.background.backgroundtaskbuilder) API with the Windows App SDK API [Microsoft.Windows.ApplicationModel.Background.BackgroundTaskBuilder](/windows/windows-app-sdk/api/winrt/microsoft.windows.applicationmodel.background.backgroundtaskbuilder).
2626

2727
## In-proc background tasks
2828

29-
In case of in-proc background tasks in UWP, background task routines are implemented in the [OnBackgroundActivated](/uwp/api/windows.ui.xaml.application.onbackgroundactivated) callback which runs as part of the foreground process. This won't be possible in a WinUI application as the **OnBackgroundActivated** callbacks aren't available. The application needs to move the background task implementations to full trust COM tasks as described above and define the COM server in the package manifest to handle the COM activation of the task. When the trigger occurs, COM activation will happen on the corresponding [COM Coclass](/windows/uwp/cpp-and-winrt-apis/author-coclasses#implement-the-coclass-and-class-factory) registered for the trigger.
29+
For in-proc background tasks in UWP, background task routines are implemented in the [OnBackgroundActivated](/uwp/api/windows.ui.xaml.application.onbackgroundactivated) callback which runs as part of the foreground process. This won't be possible in a WinUI 3 application as the **OnBackgroundActivated** callbacks aren't available. The application needs to move the background task implementations to full trust COM tasks as described above and define the COM server in the package manifest to handle the COM activation of the task. When the trigger occurs, COM activation will happen on the corresponding [COM Coclass](/windows/uwp/cpp-and-winrt-apis/author-coclasses#implement-the-coclass-and-class-factory) registered for the trigger.
3030

31-
A background task registration sample can be found [here](https://github.com/microsoft/WindowsAppSDK-Samples/tree/release/experimental/Samples/BackgroundTask).
31+
A full WinUI 3 background task registration sample can be found on [GitHub](https://github.com/microsoft/WindowsAppSDK-Samples/tree/release/experimental/Samples/BackgroundTask).
3232

33-
More details on the implementation are available [here](/windows/uwp/launch-resume/create-and-register-a-winmain-background-task). Only change would be to replace the WinRT [BackgroundTaskBuilder](/uwp/api/windows.applicationmodel.background.backgroundtaskbuilder) API with the Windows App SDK APIs in [Microsoft.Windows.ApplicationModel.Background.BackgroundTaskBuilder](/windows/windows-app-sdk/api/winrt/microsoft.windows.applicationmodel.background.backgroundtaskbuilder).
33+
More details on the implementation are available [here](/windows/uwp/launch-resume/create-and-register-a-winmain-background-task). The only change would be to replace the WinRT [BackgroundTaskBuilder](/uwp/api/windows.applicationmodel.background.backgroundtaskbuilder) API with the Windows App SDK APIs in [Microsoft.Windows.ApplicationModel.Background.BackgroundTaskBuilder](/windows/windows-app-sdk/api/winrt/microsoft.windows.applicationmodel.background.backgroundtaskbuilder).
3434

3535
## Windows App SDK BackgroundTaskBuilder API
3636

37-
This new API is created to support the full trust COM background task implementations in WinUI and other desktop applications using Windows App SDK, as the WinRT API throws exceptions during registration except for a few triggers. The following code shows how to register background task using Windows App SDK [BackgroundTaskBuilder](/windows/windows-app-sdk/api/winrt/microsoft.windows.applicationmodel.background.backgroundtaskbuilder) APIs:
37+
This Windows App SDK **BackgroundTaskBuilder** API is created to support the full trust COM background task implementations in WinUI 3 and other desktop applications that use Windows App SDK, as the WinRT API throws exceptions during registration except for a few triggers.
38+
39+
The following code shows how to register background task using Windows App SDK [BackgroundTaskBuilder](/windows/windows-app-sdk/api/winrt/microsoft.windows.applicationmodel.background.backgroundtaskbuilder) APIs:
3840

3941
```cpp
4042
//Using Windows App SDK API for BackgroundTaskBuilder
@@ -47,7 +49,7 @@ builder.SetTaskEntryPointClsid(classGuid);
4749
builder.Register();
4850
```
4951

50-
Here is the equivalent C# code:
52+
The following is the equivalent C# code:
5153

5254
```csharp
5355
// Using Windows App SDK API for BackgroundTaskBuilder
@@ -59,13 +61,13 @@ builder.SetTaskEntryPointClsid(classGuid);
5961
builder.Register();
6062
```
6163

62-
For using this API, developers would need to add a specific tag as below in their project file:
64+
To use this API, add the tag below to the project file to enable Windows App SDK background tasks:
6365

6466
``` xml
6567
<WindowsAppSDKBackgroundTask>true</WindowsAppSDKBackgroundTask>
6668
```
6769

68-
Also in the manifest file **EntryPoint** for **BackgroundTask** is set as **Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.Task**:
70+
Also, in the manifest file, the **EntryPoint** for **BackgroundTask** is set to `Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.Task`:
6971

7072
``` xml
7173
<Extension Category="windows.backgroundTasks" EntryPoint="Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.Task">
@@ -75,7 +77,7 @@ Also in the manifest file **EntryPoint** for **BackgroundTask** is set as **Micr
7577
</Extension>
7678
```
7779

78-
For C# applications, an **ActivatableClass** registration may also need to be added manually as below:
80+
For C# applications, an **ActivatableClass** registration should also be added to the manifest file:
7981

8082
```xml
8183
<Extension Category="windows.activatableClass.inProcessServer">
@@ -88,7 +90,7 @@ For C# applications, an **ActivatableClass** registration may also need to be ad
8890

8991
## Leveraging TaskScheduler for background task migration
9092

91-
[Task Scheduler](/windows/win32/api/_taskschd/) helps desktop apps in achieving the same functionality that is provided by [BackgroundTaskBuilder](/uwp/api/windows.applicationmodel.background.backgroundtaskbuilder) in UWP apps. More details on implementations using **TaskScheduler** are available [here](/windows/win32/api/taskschd/).
93+
[Task Scheduler](/windows/win32/api/_taskschd/) helps desktop apps achieve the same functionality that is provided by [BackgroundTaskBuilder](/uwp/api/windows.applicationmodel.background.backgroundtaskbuilder) in UWP apps. More details on implementations using **TaskScheduler** are available [here](/windows/win32/api/taskschd/).
9294

9395
## ApplicationTrigger use in Windows App SDK applications
9496

0 commit comments

Comments
 (0)