introduction
Background agents are scheduled tasks that run in the background and add value to your application that the other application might not have. Here we will cover everything about background agents, including their types and how and when to use them. I believe whatever app you have can be made better with the implementation of background agents, background agents keep the user in touch with the application when the application is not actually working (in other words not working in the foreground). We will look at the various ways in which we can use the background agents. Windows Phone has the philosophy "users first" and hence all the basic architecture depends on the best possible performance and battery life.
Foreground Tasks
- Normally a Windows Phone application runs in the "foreground".
- Has access to the screen and interacts directly with the user of the phone.
- At any given time only one application is running in the foreground.
- Although others may be in the memory of the phone and can be selected as required.
As mentioned above, Windows Phone follows the philosophy "users first" so the application running in the foreground is the only application, there might be other applications that have lots of memory but no CPU utilization, that is the reason Windows Phone has the most fluid interface. This is where background agents are useful; as we said, the app in the foreground is the only app running but we also need some background processing for other apps like fetching emails and so on.
So instead of running the complete application in the background we have background agents that run on behalf of the application and perform specific tasks.
Background Agents
It is a totally different project in Visual Studio and is linked to the main application, it can interact with the background storage of the Windows Phone and can share data, but actually it is a totally different piece of code. On the basis of consuming processor resources we have two types of background agents:
- PeriodicTask
- ResourceIntensiveTask
There is only one agent allowed per application, and an agent can never be compared with the foreground application running in the background siince it has certain limitations. A background agent is limited in what it can do and the access it has to the processor and other phone facilities.
Background Agent Health Warning
The Operating System manages all the background agents, you can go to the settings and manage all your running background agents as in the following:
- The number of background agents is limited per application (in other words 1 per app)
- If the right conditions do not exist then the agent will not be started.
- Background agents run only in the situation whenever the operating system feels able to give them the processor to access.
- If the phone gets into "Power Saver" mode then it may stop running the background agents completely
- The user may not use agents to provide fundamental behaviors therefore:
- A background agent is the cherry on top, not the ice-cream.

Comments
Join the conversation! Your thoughts help the community grow.