© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago
apcr

How to start a background service using Package.appxmanifest?

can someone please help me to add a Background Service to my Avalonia UI app that's delivered through an appx?

I have two projects in my solution:
1. MyApp.UI - Avalonia UI project
2. MyApp.UI.Installer - Application Packaging Project for creating an APPX installer

Here's what I tried initially:

1. First, in MyApp.UI, I created a file called PushNotificationBackgroundService.cs:
public class PushNotificationBackgroundService : IBackgroundTask
{
    // Entry point that should eventually be called
    public async void Run(IBackgroundTaskInstance taskInstance) {...}
}
public class PushNotificationBackgroundService : IBackgroundTask
{
    // Entry point that should eventually be called
    public async void Run(IBackgroundTaskInstance taskInstance) {...}
}

2. Then, in MyApp.UI.Installer, I added a reference to MyApp.UI.
3. After that, in MyApp.UI.Installer, I edited the Package.appxmanifest file to add an Extension for the existing application:
<Applications>
    <Application Id="App"
                 Executable="$targetnametoken$.exe"
                 EntryPoint="$targetentrypoint$">
        <Extensions>
            <Extension Category="windows.backgroundTasks" EntryPoint="$targetentrypoint$.PushNotificationBackgroundService">
                <BackgroundTasks>
                    <Task Type="pushNotification"/>
                </BackgroundTasks>
            </Extension>
        </Extensions>
    </Application>
</Applications>
<Applications>
    <Application Id="App"
                 Executable="$targetnametoken$.exe"
                 EntryPoint="$targetentrypoint$">
        <Extensions>
            <Extension Category="windows.backgroundTasks" EntryPoint="$targetentrypoint$.PushNotificationBackgroundService">
                <BackgroundTasks>
                    <Task Type="pushNotification"/>
                </BackgroundTasks>
            </Extension>
        </Extensions>
    </Application>
</Applications>


The package compiles, the app installs and opens, but the PushNotificationBackgroundService isn't visible anywhere. There are no errors in the Event Viewer, and it's not showing up in processes. I even tried writing to a log file to see if it was running, but there's no file.

What am I doing wrong? Are there other ways to do this without using MSIX? Maybe directly from Program.cs?

I tried different values for the EntryPoint attribute:
- EntryPoint="$targetentrypoint$.PushNotificationBackgroundService"
- EntryPoint="MyApp.UI.PushNotificationBackgroundService"
- EntryPoint="PushNotificationBackgroundService"

Nothing seems to work
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

✅ Failing to start custom background service
C#CC# / help
3y ago
✅ SignalR in a background service
C#CC# / help
2y ago
Background Service and Blazor
C#CC# / help
2y ago
Background service to consume a rabbitmq queue, messages unacked
C#CC# / help
3y ago