The key difference between resource-intensive agents and other background agents is that resource-intensive agents for auto-upload applications do not expire, even if the auto-upload application is not invoked. Resource intensive agents can be restricted to the connect mode they will operate in (for example, WIFI only).

Let us walk through the steps to build an application that supports auto-upload .

Hands On

Open Visual Studio 2012 and create a new Windows Phone project called WindowsPhoneAutoUploadDemo.

Next, we need to create a page, which will be called when we navigate to Settings application and select our application, because we want to directly offer the auto upload settings supported by our application. Let us add a new page to our project. We will call this page “ConfigureUpload.”

Add a new XAML page called “ConfigureUpload.xaml.”

Rename our newly created page to be titled “Configure Upload.”

Next, we will add a class, which will be responsible for Registering the ConfigureUpload URI to our project.

Add a class

In this class, we will implement logic to return the URI for the application configuration page if it contains the phrase “ConfigureUpload”.

Next, we will go back to working on the WindowsPhoneAutoUploadDemo project. Add a dependency on the UploadScheduledTaskAgent project.

In MainPage.xaml.cs, we add a variable of type ResourceIntensiveTask.

Now, we will add a method, which does the work of starting our resource intensive agent.

Let’s call that method StartResourceIntensiveTask. In this method, we will implement the logic to create a new ResourceIntensiveTask object and call the method, which does the actual uploading of the file. Note that this demo project does not contain an actual implementation of upload. You can find APIs for DropBox and Flicker on CodePlex if you want to build an application to support these storage platforms.

publicvoid StartResourceIntensiveTask()
{
if (resourceIntensiveTask != null)
{
ScheduledActionService.Remove("ResourceIntensiveAgent");
}
resourceIntensiveTask = newResourceIntensiveTask("ResourceIntensiveAgent");ScheduledActionService.Add(resourceIntensiveTask);
StartUpload();
// Place the call to Add in a try block in case the user has disabled agents.
}
publicvoid StartUpload()
{
// Implement the logic to upload the file here. You will need to authenticate as well as provide support to upload a file
}

Finally, we will add a UI element, which will initialize the upload. For this, we will add a button called “Upload” and on its click event we will call the StartResourceIntensiveTask() method.

Vipul Patel is a Program Manager currently working at Amazon Corporation. He has formerly worked at Microsoft in the Lync team and in the .NET team (in the Base Class libraries and the Debugging and Profiling team). He can be reached at vipul_d_patel@hotmail.com