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

- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire
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
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us
Popular tags
Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 windows Phone 7 windows Phone 8
programming4us programming4us
 
programming4us
Natural Miscarriage
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Game Trailer