Share via


How to use the Update Task (XAML)

[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]

The Update Task is a background task that is invoked by the operating system after the user installs an update to an app that is installed on the device. This allows your app to perform initialization tasks, such as initializing a new push notification channel, without requiring the user to launch your updated app.

What you need to know

Technologies

Prerequisites

  • This topic assumes that you have an app that you are planning to update to a newer version.

Instructions

Step 1: Create a Background Task project for your app

As with other types of background tasks, you implement the Update Task in a Windows Runtime component. To create this component, follow the steps in the "Create the Background Task class" section of Quickstart: Create and register a background task. The steps include:

  • Adding a Windows Runtime Component project to your solution.
  • Creating a reference to the component in your foreground app.
  • Creating a class in the component that implements IBackgroundTask.
  • Implementing the Run method that is called by the system when your background task is run. The Quickstart explains how to use a deferral in your Run method if you are going to make asynchronous calls.

You don't need to go through the "Register the background task to run" section of the Quickstart to use the Update Task. The fundamental reason to use an Update Task is that it runs before the user launches your updated app, so you don't need to add any code to your foreground app to register the task.

Step 2: Add the Update Task to the app manifest

In Solution Explorer, double click Package.appxmanifest to open the Manifest Designer. On the Declarations tab, from the Available Declarations list, select Update Task and click Add. Under Properties, in the Entry point field, enter the path to the IBackgroundTask class you implemented in the previous step using the format namespace.classname.

Step 3: Add your app's update code to your background task

Now that your app's Update Task is configured, you simply add code to the Run method of your background task to perform whatever actions you need after your updated app is installed. A common scenario for an Update Task is to set up a push notification channel for your updated app so that your app will receive notifications before the user runs your updated app for the first time. For information on setting up a push notification channel, see How to request, create, and save a notification channel.

Step 4: Test your Update Task

To test your Update Task, you will need to use the Application Deployment tool to install the initial version of your app and then install your updated app using the /update flag, at which point your Update Task will run. For more information on using this tool, see Deploy Windows Phone apps with the Application Deployment tool.

Supporting your app with background tasks