Running code in the background
[This article is for Windows 8.x and Windows Phone 8.x developers writing Windows Runtime apps. If you’re developing for Windows 10, see the latest documentation]
You can run a task in the background to perform work when your main app is not running.
Although Windows Store apps can't run while in the background (that is, when they are suspended or terminated), there are specific circumstances when you can run code when your app isn't in the foreground. These include:
- Playing audio
- Uploading or download files
- When a portion of the app, known as a task, is configured to run when certain conditions are met, including a timer event and notifications.
- Updating a live tile with fresh information,
- Updating an item on the lock screen.
Playing audio in the background
Playing audio is a special type of background task. See How to play audio in the background.
Uploading and downloading files
Updating a live tile
Windows 8 uses live tiles (see Tiles, badges, and notifications) to provide up-to-date information. See Quickstart: Update a live tile from a background task for details on refreshing a tile even when your app isn't running.
Updating a lock screen item
The Windows 8lock screen can display up to seven app status icons (such as email, instant messaging and calendar apps). An app that registers to display on the lock screen can refresh its information every fifteen minutes. For example code, see Quickstart: Showing tile and badge updates on the lock screen (Windows Store apps).
Topics for iOS devs
Background task topics