The Mysteries of Mango's Multitasking

Published by at

Each mobile operating system has its own way of multitasking. As such, Windows Phone 7.5 has its own unique way too, which might be somewhat strange if you're coming from, say, Symbian. Even if you're not a developer, it can be useful to know why your phone works as it does, and so here is our guide to understanding the nuts and bolts beneath the hood of your Windows Phone.

Task Switching

The multitasking in Windows Phone 7.5 Mango is perhaps something of a misnomer, as only the application currently on screen is running at any one time. However, that is not to say that Mango cannot do more than one thing at once.

Whenever you switch away from an application it stops running, and is rendered dormant, stored in RAM. By analogy, compare this to putting your computer into standby where your RAM is still powered up. This enables the 'fast application switching' which is accessed when you hold the back button and view the list of application previews.

WP7.5 Application Execution

The execution model for Windows Phone 7.5 Mango applications (source).

If the phone needs more RAM, it creates space by "tombstoning" an application. Taking the PC analogy again, this is similar to when a PC hibernates by dumping RAM to hard drive. In the case of Windows Phone 7.5 the application is closed down, but everything you were doing in the application is saved in RAM. That is why the 'Resuming' screen is shown, as your phone is actually launching the application and restoring it to the state you left it in.

You should note that resuming from dormant or tombstoned states only works from the 'Fast App Switching' screen. Re-launching an application from the start screen always opens a completely new instance of the application. [Somewhat controversially. You may remember my impassioned editorial rant? - Ed]

Background Tasks

As mentioned already, the programs that you interact with via the touchscreen do not run in the background. However, every application can have an associated program – usually called an agent – that can run in the background. The ways in which an 'agent' can run are heavily prescribed with a set amount of modes in which they can operate.

Background audio: A process can play audio in the background with controls available via the Zune player, these appear whenever you press the volume controls. Developers can use the built-in Zune software to play the audio or they can implement their own playback software (i.e. codec).

Scheduled tasks: Code can be written for an application which is automatically executed by your phone at set intervals; i.e. a background agent. There are two types of scheduled task, which we'll return to later.

Background file transfers: Agents running for a given application can queue up a list of files to be downloaded or uploaded while the application is not in the foreground. There are some limitations to this: you cannot upload a file larger than 5MB on any type of connection, maximum download size is 20MB for cellular data and 100MB for WiFi connections when not on external power.

Lumia 800 DC-16 Nokia

Most file transfers will occur while you recharge your device

Scheduled Tasks

The real background multitasking in Windows Phone 7.5 is done with scheduled tasks. As the name implies, they are limited to only running on a set schedule – i.e. they cannot run persistently – and they can only run for a small amount of time before the system shuts them down. There are two types of scheduled task: "Periodic Agents" run for no more than 25 seconds, and can be activated on a recurring interval of 30 minutes; "Resource-Intensive Agents" run can run for up to 10 minutes, and typically they are used for synchronising or transferring large amounts of data while you're not using your phone.

Periodic Agents can be used for a range of tasks such as posting your location to a cloud service, triggering a toast notification, synchronising a small amount of data, updating a live tile, etc. Indeed, the last two examples are often used together. Note that these types of tasks can be disabled by the battery saver mode. You can tell if an application is using a periodic task, as its settings page will have an option for 'update frequency' (e.g. 30 minutes, 1 hour, 2 hours, etc.).

Example of setting a period task schedule and disabling all agents with battery saver mode.

Resource-Intensive Agents can have many more restrictions set on their operation, due to their relatively high power consumption. A developer may opt to limit such an agent by requiring external power, WiFi, screen lock, no phone calls, battery level above 90%, etc. A well designed application should make you aware of these limits, without blinding you with science!

Podcast downloads are examples of tasks that usually require external power and/or WiFi

Notifications and Tiles

Notifications in Windows Phone 7.5 can come in two forms: via live tiles or through toast notifications (e.g. calendar reminders). They can be triggered in two ways too: Scheduled Notifications are a special type of task, an example of which is an alarm, whereby tapping the toast bar takes you to the application; Push Notifications are triggered via an external service on the Internet. As with scheduled notifications, push notifications can be used to both update live tiles and trigger toast notifications which, when tapped, will launch the application to a corresponding page.

Push notifications are quite costly to set up. To start with, a developer will need to fund and operate a server to handle the data that will ultimately be 'pushed' to your phone.  Then, to complicate matters, a server cannot send a push notification directly to a Windows Phone. Instead, all notifications have to be relayed through the Microsoft Push Notification Service (MPNS).


Schematic of push notifications in Windows Phone via MPSN (source)

For example, Twitter, Rowi, and Whatsapp use MPNS, which is why you will get an instant notification when someone contacts you. Conversely, Skype does not receive push notifications in the background (but it could!) which is why you can only receive messages and calls while it is running and on screen.  Most Twitter clients are currently not using MPSN either, and is why they cannot inform you of replies and messages more frequently than every 30 minutes – i.e. they are using periodic tasks to sync directly with Twitter.

Corollaries of Mango Multitasking

As an end user, it helps to keep the following in mind:

  1. Your device behaves in such a way to be as frugal with power and cellular data as it can.
  2. In light of #1, tasks like large file transfers and heavy processing will probably not take place until your device is connected to external power and WiFi.
  3. Gaming is not covered by #1 and #2 as it is not a background activity.
  4. Battery saver mode will disable push notifications and stop all background activity by third party apps.
  5. When comparing certain types of applications, you should check for push notification support.
  6. Launching an application from the Start Screen opens a new instance of the application. If you want to return to an application in the state you left it in, you need to use the Fast Task Switching feature by holding the Back button.
  7. If you use Fast Task Switching (#6), be aware that applications are not held in RAM indefinitely. The longer it has been since you used an application, the more likely it is that you will have to wait a few seconds while it reloads and set itself back to the state you left it in.

Further Reading [MSDN]



I'd like to thank Richard Castle from Igneous Software (BBC Podcast Lounge) and the developer of Nextgen Reader for their time and advice for this article.