IT tutorials
 
Technology
 

Windows Phone 8 : Background Agents (part 2) - Resource-Intensive Agent

8/17/2013 11:08:29 AM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

2. Resource-Intensive Agent

Like a periodic agent, a resource-intensive agent is a repeatable task that performs some discrete process in the background. Unlike the periodic agent, though, the resource-intensive agent is not meant to be executed very often. In fact, there are a strict set of rules as to when resource-intensive agents are executed. These agents are meant to be able to run for a longer period (up to 10 minutes) and consume more resources (for instance, network, and memory). But to allow your agent to be executed, the operating system must only allow it when doing so is not detrimental to the phone itself. To that end, the criteria for executing a resource-intensive agent include

• On external power

• When using a noncellular network (for example, Wi-Fi or plugged into a PC)

• When the minimum battery level is 90%

• When the device must be screen-locked

• When no phone call is active

These rules should imply the fact that resource-intensive agents are meant for syncing large amounts of data or processing that will be accomplished occasionally. These agents are often executed only once a day, at most. Deciding whether to use an agent (or deciding to use a periodic agent or resource-intensive agent) can increase the overall usefulness of your application.

If the criteria for executing a resource-intensive agent change while the agent is being executed (for instance, a phone call comes in or the phone is removed from external power), the resource-intensive agent will immediately be aborted to allow the user full access to the phone.


Warning

Resource-intensive agents have so many requirements to enable them to be executed that some users will never be able to execute these agents. For example, users who don’t dock their phone with a PC or use Wi-Fi will never execute a resource-intensive agent.


Both resource-intensive and periodic agents are scheduled agents. So whether you’re adding a periodic or a resource-intensive agent (or even if you need both), you will have a single Scheduled Task Agent project .

Registering a resource-intensive agent is virtually identical to registering a periodic agent:

// A unique name for your task. It is used to
// locate it in from the service.
var taskName = "IntensiveTask";

// If the task exists
var oldTask = ScheduledActionService.Find(taskName);
if (oldTask != null)
{
  ScheduledActionService.Remove(taskName);
}

// Create the Task
ResourceIntensiveTask task = new ResourceIntensiveTask(taskName);

// Description is required
task.Description = "This does a lot of work.";

// Add it to the service to execute
ScheduledActionService.Add(task);

The only real difference is that the class you create is an instance of ResourceIntensiveTask (instead of PeriodicTask). By specifying that the new task is a resource-intensive task, the operating system will know to execute the agent only when the phone is ready for a resource-intensive operation (for example, it is in a state as defined by the previously mentioned limitations).

You can test resource-intensive agents in the same way as well, by calling the ScheduledActionService’s LaunchForTest method:

var taskName = "IntensiveTask";

ScheduledActionService.LaunchForTest(taskName,
  TimeSpan.FromMilliseconds(10));

You might want to have both a periodic and a resource-intensive task registered for the phone. The problem is that an application can have only a single background agent (the Scheduled Task Agent project) associated with an application. You can register one (and only one) of each type of scheduled task. This means you can have a periodic task and a resource-intensive task for your application, but because there is only one agent, you must discriminate which type of task is being called in your agent by checking the task type, like so:

public class ScheduledAgent : ScheduledTaskAgent
{
  protected override void OnInvoke(ScheduledTask task)
  {
    if (task is ResourceIntensiveTask)
    {
      DoHeavyResources();
    }
    else
    {
      DoPeriodic();
    }

    NotifyComplete();
  }

  // ...
}

In this way, you can determine the type of task the OnInvoke is meant to execute. You could discriminate by name as well, but because you can have only one of each type, testing by object type is just as effective.


 
Others
 
- Windows Phone 8 : Background Agents (part 1) - Periodic Agent
- Active Directory 2008 : Configuring Computer Accounts - Supporting Computer Objects and Accounts
- Active Directory 2008 : Automating the Creation of Computer Objects
- Administration of Microsoft Lync Server 2010 : Troubleshooting (part 2) - Lync Server Logging Tool
- Administration of Microsoft Lync Server 2010 : Troubleshooting (part 1)
- Administration of Microsoft Lync Server 2010 : Configuring Quality of Service
- Administration of Microsoft Lync Server 2010 : Management Tasks
- Windows 8 : Maintaining Data Access and Availability - Managing Offline Files (part 3) - Configuring Disk Usage Limits for Offline Files
- Windows 8 : Maintaining Data Access and Availability - Managing Offline Files (part 2) - Managing Offline File Synchronization
- Windows 8 : Maintaining Data Access and Availability - Managing Offline Files (part 1) - Making Files or Folders Available Offline
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us