Guidelines for background tasks (Windows Store apps)
Create better background tasks to support your Windows Store app and ensure your app meets the requirements for running background tasks.
Consider the following guidance when developing your background task, and before publishing your app.
CPU and network quotas: Don't exceed the CPU quota or network data usage quota applied to your background task. Background tasks should be lightweight to save battery life and provide a better user experience for foreground apps. See Supporting your app with background tasks for the resource constraints applied to background tasks.
Manage background tasks: Your app should get a list of registered background tasks, register for progress and completion handlers, and handle those events appropriately. Your background task classes should report progress, cancellation, and completion. For more info see How to get a list of pending background tasks, How to handle a cancelled background task, and How to monitor background task progress and completion.
Use BackgroundTaskDeferral: If your background task class runs asynchronous code, make sure to use deferrals. Otherwise your background task might be terminated prematurely when the Run method completes. For more information, see Quickstart: Create and register a background task.
Alternatively, request one deferral, and use async/await to complete asynchronous method calls. Close the deferral after the await method calls.
Update the app manifest: Declare each background task in the application manifest, along with the type of triggers it is used with. Otherwise your app will not be able to register the background task at runtime. For more information, see How to declare background tasks in the application manifest.
Prepare for app updates: If your app will be updated, create and register a ServicingComplete background task (see SystemTriggerType) to help perform app updates that may be necessary outside the context of running in the foreground.
Background tasks for lock screen-capable apps: The lock screen is a shared resource. Only seven apps may be placed on the lock screen at any one time, and only one may show a wide tile. Your app can provide a good user experience by requesting lock screen access using the RequestAccessAsync method, and by making sure your app will still work without being on the lock screen. Apps that are not placed on the lock screen can still update tiles, update badges, send notifications, and register for system event triggers. The user experience when your app is in the foreground should never be disrupted even if the user has not placed your app on the lock screen.
Read the Lock screen overview to get a sense for whether or not the lock screen is the right place for your app.
The following checklist applies to all background tasks.
Associate your background task with the correct trigger.
Add conditions to help ensure your background task runs successfully.
Handle background task progress, completion, and cancellation.
Do not display UI other than toasts, tiles, and badge updates from the background task.
In the Run method, request deferrals for each asynchronous method call, and close them when the method is done.
Or, use one deferral with async/await.
Use persistent storage to share data between the background task and the app.
Declare each background task in the application manifest, along with the type of triggers it is used with. Make sure the entry point and trigger types are correct.
Write background tasks that are short-lived. Don't exceed the CPU or network quotas shown in Supporting your app with background tasks.
Do not rely on user interaction in background tasks.
Don't specify an Executable element in the manifest unless you are using a trigger that should be run in the same context as the app (such as the ControlChannelTrigger).
Check for background task registration errors. If appropriate, attempt to register the background task again with different parameter values.
Follow this guidance when developing background tasks for apps that are capable of being on the lock screen. Follow the guidance in Guidelines and checklist for lock screen tiles.
Make sure your app needs to be on the lock screen before developing it as lock screen-capable. For more info see Lock screen overview.
Make sure your app will still work without being on the lock screen.
Request lock screen access using the RequestAccessAsync method.
Include a background task registered with PushNotificationTrigger, ControlChannelTrigger, or TimeTrigger and declare it in the app manifest. Make sure the entry point and trigger types are correct. This is required for certification, and enables the user to place the app on the lock screen.
Write background tasks that are short-lived, even for lock screen-capable apps. Don't exceed the CPU or network quotas shown in Supporting your app with background tasks.
- Quickstart: Create and register a background task
- How to register a background task
- How to declare background tasks in the application manifest
- How to debug a background task
- How to trigger suspend, resume, and background events in Windows Store apps (when debugging)
- Other related lock screen guidance
- Lock screen overview
- Displaying tiles on the lock screen
- Guidelines and checklist for lock screen tiles