Does Windows App SDK need better support for periodic background tasks? #2322
Unanswered
JosHuybrighs
asked this question in
Q&A
Replies: 1 comment 13 replies
-
Great questions! I'd normally say to use the Timer-triggered BG task. Hey @andreww-msft and @aeloros - seems like a great "make background tasks easier" space. Do you have a good example of wiring up a bg task that drives the activation into a running app, like the other AppLifecycle work you've done? |
Beta Was this translation helpful? Give feedback.
13 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am porting my SyncFolder UWP/Desktop-Bridge app to a WinUI 3 - Desktop app (using Windows App SDK 1.0 and a package/wap project).
My app allows users to configure sync/backup tasks for selected folders and target devices and allows users to automatically schedule these tasks using a configured time schedule.
In the current UWP/DesktopBridge version the scheduling occurs with a UWP timer-triggered background task, which every 15 minutes checks whether a task is due and if so launches a win32 project to do the actual copying/syncing.
The win32 process uses a
AppService Connection
to communicate status and progress with the UI user-app in case the user would have opened the app.With WinUI3-Desktop I can finally get rid of the unreliable
AppService Connection
because it allows me to have a single app/process that can both show the UI when necessary or run hidden and execute the sync/backup tasks when triggered in the background.The challenge with Windows App SDK now is: which concept to use for running a periodic task?
There seems to be 3 possible approaches, but none of them offers enough capabilities.
Timer-triggered background task, as it is done in UWP.
Today this requires an OOP background task and, if you follow the description I gave in an earlier discussions topic #2314, is not so difficult to do.
The major problem however with this concept is that such a task doesn't run while the screen is in lock state. That is not ideal for the kind of app I am publishing.
A startup-task that periodically executes code.
Such task would be added to the package and will do whatever it needs to do (check if sync/copy tasks are due in my case), wait 15 minutes, check again. It will keep on doing this until the task gets killed.
This is relatively simple to implement using
Application.Run(context)
in a windows forms project (without an active window) and aTimer
that fires every 15 minutes. It also seems to allow that execution keeps on occurring while in the lock screen.2 problems however with this:
That seems to be the ideal solution since it allows execution to happen in all kind of circumstances, like in lock screen, force to go out of sleep state, etc.
The major issue however with this is that there is no possibility to deregister the app from the Task Schedular when the app is uninstalled.
Windows App SDK supports a UpdateTask (to support app updates) but there is no "UninstallTask".
Maybe of interest: there is an issues topic #16 that discusses the need to support 'uninstall' in the MSIX manifest and support for a Uninstall-task.
I am interested to learn how other people would approach this. Support for a "UninstallTask" seems to be a good solution for everyone who doesn't want to use a seperate installer product.
Beta Was this translation helpful? Give feedback.
All reactions