Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Phone

Windows Phone 8 : Scheduled Tasks - Updating Tiles Using a Scheduled Task Agent

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
9/10/2014 4:29:03 AM

The background agent for the sample is the TaskScheduler class, which is a subclass of the ScheduledTaskAgent class. TaskScheduler is registered using the WMAppManifest.xml file.

As you saw earlier, a periodic task is registered in the TodoItemViewModel class. This causes the TaskScheduler.OnInvoke method to be called periodically. The OnInvoke method determines what kind of task is being launched by the OS, either periodic or resource intensive. For the to-do sample, it is always a periodic task (see Listing 1).

LISTING 1. TaskScheduler OnInvoke Method (excerpt)


protected override void OnInvoke(ScheduledTask task)
{
    /* Detect if the task is periodic or resource intensive. */
    if (task is PeriodicTask)
    {
        ProcessPeriodicTask();
    }
    else
    {
        ProcessResourceIntensiveTask();
    }
...
    NotifyComplete();
}


The main purpose of the TaskScheduler is to refresh the shell tiles on the Start Experience, updating the overdue status and changing the background image as required (see Listing 2).

The ProcessPeriodicTask method retrieves all tiles for the app containing the to-do item query string parameter. Each tile is processed by extracting the Id of the to-do item, and then by retrieving the actual TodoItem object using the to-do service. A new StandardTileData object is created for the TodoItem using the TodoTileDataCreator, and the tile is updated.

LISTING 2. TaskScheduler ProcessPeriodicTask Method


void ProcessPeriodicTask()
{
    TodoService todoService = new TodoService();

    string queryWithEquals = TodoItemIdQueryKey + "=";
    IEnumerable<ShellTile> tiles = ShellTile.ActiveTiles.Where(
            tile => tile.NavigationUri.ToString().Contains(queryWithEquals));

    foreach (var tile in tiles)
    {
        /* NavigationUri.Query raises an exception on relative URIs. */
        Dictionary<string, string> queryPairs
            = UrlUtility.ParseQueryString(tile.NavigationUri.ToString());
        string idString = queryPairs[TodoItemIdQueryKey];
        int todoItemId;
        if (!int.TryParse(idString, out todoItemId))
        {
            Debug.Assert(false, "Invalid id " + idString);
            continue;
        }

        TodoItem todoItem;
        if (!todoService.TryGetTodoItem(todoItemId, out todoItem))
        {
            Debug.Assert(false, "Unknown item " + idString);
            continue;
        }

        StandardTileData tileData = TodoTileDataCreator.CreateTile(
                                                 todoItem.Description,
                                                 todoItem.DueDate);
        tile.Update(tileData);
    }
}


Using a scheduled task agent to update shell tiles provides the means to engage with your users even when your app is not running. It should be remembered, however, that there is no guarantee that a scheduled task will run; therefore, it is wise not to depend solely on a background task for activities critical to the proper functioning of your app. Indeed, updating of shell tiles should also be done within your foreground app, which is not done in the sample.

Other -----------------
- Windows Phone 8 : Scheduled Tasks - To-Do List Scheduled Task Sample (part 5) - Editing an Existing To-Do Item
- Windows Phone 8 : Scheduled Tasks - To-Do List Scheduled Task Sample (part 4) - Creating the To-Do Item Shell Tile, Saving a To-Do Item
- Windows Phone 8 : Scheduled Tasks - To-Do List Scheduled Task Sample (part 3) - Debugging Scheduled Tasks
- Windows Phone 8 : Scheduled Tasks - To-Do List Scheduled Task Sample (part 2) - TodoService, TodoItemViewModel
- Windows Phone 8 : Scheduled Tasks - To-Do List Scheduled Task Sample (part 1) - TodoItem,TodoDataContext
- Windows Phone 8 : Scheduled Tasks - Using Scheduled Tasks
- Windows Phone 8 : Scheduled Tasks - Background Agent Types
- 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
 
 
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
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server