Logo
HOW TO
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
 
 
Windows Phone

Windows Phone 8 : Scheduled Tasks - Background Agent Types

9/10/2014 4:19:07 AM

Windows Phone supports three types of background agents: ScheduledTaskAgent, AudioPlayerAgent, and AudioStreamingAgent (see Figure 1).

Image

FIGURE 1 BackgroundAgent types.

ScheduledTaskAgent is an abstract class, which you subclass to provide your own logic to be performed whenever the OS chooses to invoke your agent. When invoked, the OS passes the registered task object to the task agent, which allows you to determine what kind of activity is to be performed.

ScheduledTaskAgents handle two kinds of tasks: periodic and resource intensive, which are represented by the PeriodicTask and ResourceIntensiveTask classes, respectively.


Note

An app may have only one periodic task and/or one resource intensive task. If an attempt is made to register more than one of either type, an InvalidOperationException is raised.


Scheduled tasks are registered in the same manner as ScheduledNotification objects—with the ScheduledActionService. At an indeterminate time after registration, the operating system instantiates your task agent and passes it the scheduled task (see Figure 2). The agent performs any processing it needs to do in the background, and then signals that it has either completed its work or that it is unable to complete.

Image

FIGURE 2 Periodic tasks are registered with the ScheduledActionService. The OS invokes the ScheduledTaskAgent, passing it the PeriodicTask object.

It is important to recognize the distinction between the roles of tasks and task agents. Tasks contain information that is passed to the task agent. Their purpose is to allow the ScheduledActionService to determine how and when to run the task agent. The task agent performs the background activity, and that is where you can place your code to be executed in the background.

PeriodicTask and ResourceIntensiveTask are analogous to the ScheduledNotification classes: Alarm and Reminder. ScheduledTask and ScheduledNotification both derive from ScheduledAction, which includes properties for the name and expiration date of the task (see Figure 3).

Image

FIGURE 3 ScheduledTask is derived from ScheduledAction, the same base class for scheduled notifications.

The following sections examine the two ScheduledTask types, PeriodicTask and ResourceIntensiveTask, in greater detail.

Periodic Tasks

A periodic task is used to perform short operations and is allocated a 15-second window to complete its work. Periodic tasks run, at most, every 30 minutes. Typical scenarios for periodic tasks include performing small incremental data synchronization with a cloud service, using geographic location to track the location of the device, or polling a social network cloud service for new messages or status updates.


Note

When retrieving the geographic location of the device within a scheduled task (via a GeoCoordinateWatcher), a cached location value is used instead of real-time data. This helps to minimize the power consumption of background agents. It does, however, also introduce a lag for determining the location of the device, which may be problematic in some scenarios.


Periodic Task Invocation

There are no guarantees that a periodic task will ever run. To minimize resources, the phone OS launches all periodic tasks for all apps on the device at approximately the same time. This can mean that if a large number of periodic tasks are registered, not all will be invoked. Moreover, Battery Saver mode is an option that the user can enable on the device to indicate that battery life should be prioritized. If this mode is enabled, periodic agents may not run, even if the task interval has elapsed.

There is also a limit on the total number of periodic agents that can be scheduled on a device. This limit varies from device to device, but it can be as low as six. If this limit is approached, the user is warned that multiple background agents are running, and that it may cause faster battery consumption.

Resource Intensive Tasks

Resource intensive tasks (also known as on idle tasks) are allocated a substantially longer execution time than periodic tasks. Resource intensive tasks, however, run only when the phone meets a minimum set of requirements relating to processor activity, power source, and network connection type (see Table 1). This task is typically used to synchronize large amounts of data to the phone during periods of inactivity.

Resource intensive tasks typically run for a maximum of 10 minutes. The runtime is cut short, however, if one or more of the requirements that determine eligibility to launch are no longer met.

TABLE 1. Run Eligibility Requirements for Resource Intensive Tasks

Image

Caution

Due to the hefty requirements for resource intensive tasks, it is possible that a resource intensive task may never be launched. Be mindful of this when designing your app, and allow your foreground app to adapt to the absence of any processing that should have taken place in the background but did not.


Other -----------------
- Windows Phone 8 : Windows Phone Toolkit Animated Page Transitions - Reusing the Transition Attached Properties
- Windows Phone 8 : Windows Phone Toolkit Animated Page Transitions - Using Windows Phone Toolkit Transitions
- Windows Phone 8 : Messaging - Composing a New Message (part 8) - Checking for New Mail
- Windows Phone 8 : Messaging - Composing a New Message (part 7) - Adding Emoticons and Clip Art
- Windows Phone 8 : Messaging - Composing a New Message (part 6) - Adding Recipients Through CC and Blind CC
- Windows Phone 8 : Messaging - Composing a New Message (part 5) - Setting Message Priority
- Windows Phone 8 : Messaging - Composing a New Message (part 4) - Removing a Message Attachment
- Windows Phone 8 : Messaging - Composing a New Message (part 3) - Sending a Picture from the Camera
- Windows Phone 8 : Messaging - Composing a New Message (part 2) - Adding Message Attachments
- Windows Phone 8 : Messaging - Composing a New Message (part 1) - Writing a Message
 
 
REVIEW
- First look: Apple Watch

- 10 Amazing Tools You Should Be Using with Dropbox

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
 
VIDEO TUTORIAL
- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 1)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 2)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 3)
 
Popular tags
Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS
Popular keywords
HOW TO Swimlane in Visio Visio sort key Pen and Touch Creating groups in Windows Server Raid in Windows Server Exchange 2010 maintenance Exchange server mail enabled groups Debugging Tools Collaborating
Top 10
- Microsoft Excel : How to Use the VLookUp Function
- Fix and Tweak Graphics and Video (part 3) : How to Fix : My Screen Is Sluggish - Adjust Hardware Acceleration
- Fix and Tweak Graphics and Video (part 2) : How to Fix : Text on My Screen Is Too Small
- Fix and Tweak Graphics and Video (part 1) : How to Fix : Adjust the Resolution
- Windows Phone 8 Apps : Camera (part 4) - Adjusting Video Settings, Using the Video Light
- Windows Phone 8 Apps : Camera (part 3) - Using the Front Camera, Activating Video Mode
- Windows Phone 8 Apps : Camera (part 2) - Controlling the Camera’s Flash, Changing the Camera’s Behavior with Lenses
- Windows Phone 8 Apps : Camera (part 1) - Adjusting Photo Settings
- MDT's Client Wizard : Package Properties
- MDT's Client Wizard : Driver Properties
 
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
2015 Camaro