Edit

Run code in the background

For .NET apps that need to execute code when the app isn't running, there are three approaches depending on your packaging and workload:

Approach Packaging required Best for
Windows App SDK background tasks Yes (MSIX) Power-efficient system-managed triggers (time/system)
Task Scheduler No Periodic sync, unpackaged apps
.NET Worker Services No Long-running headless workloads, any deployment model

For Windows App SDK background tasks, your .NET app registers a COM component using BackgroundTaskBuilder just like a WinUI 3 app — the Application.Startup event in WPF maps to the role that App.OnLaunched plays in WinUI 3. See Using background tasks in Windows apps for the full walkthrough.

Note

Windows App SDK background tasks require MSIX packaging. For unpackaged .NET apps, use Task Scheduler or .NET Worker Services instead.