Periodic Task
Periodic agents run for a small amount of time on a regular recurring interval. Typical scenarios for this type of task include uploading the device’s location and performing small amounts of data synchronization.
ResourceIntensive Task
Resource-intensive agents run for a relatively long period of time when the phone meets a set of requirements relating to processor activity, power source, and network connection. A typical scenario for this type of task is synchronizing large amounts of data to the phone while it is not being actively used by the user.
Life cycle
The code for the agent is implemented by the application in a class that inherits from BackgroundAgent.
When the agent is launched, the operating system calls OnInvoke(ScheduledTask). In this method, the application can determine which type of ScheduledTask it is being run as, and perform the appropriate actions.
When the agent has completed its task, it should call NotifyComplete() or Abort() to let the operating system know that it has completed. NotifyComplete should be used if the task was successful. If the agent is unable to perform its task – such as a needed server being unavailable - the agent should call Abort, which causes the IsScheduledproperty to be set to false.
The foreground application can check this property when it is running to determine whether Abort was called.
1. WMAppmanifest.xml configuration
2. App.xaml.cs, App_Launching/App_Closing
3. Reference to Schedule Agent project
4. Write code in .cs file