If you’ve worked with Windows Phone 7 Live Tiles, you may have noticed a bit of a hole in the platform SDK’s functionality – the inability to programmatically update the current running applications tile without the push coming from a remote webserver. The purpose of this post is to show you that this is not the end of the world, and there is a way around this.

What you usually want to do with a live tile and it’s schedule is something along the lines of:

Update the live tile with a web Url “right now”

Set the phone’s operating system to fetch new versions of this Url on a schedule

The problem is, this is currently not possible. It is easy to set a schedule, but debugging this is hell as you have to wait an hour to see the result.

The current state of affairs for live tile “schedules”

The way Windows Phone 7 Live Tile schedule functionality is basically the following:

The Windows Phone 7 application starts a “schedule” with the operating system to go and fetch a static URL and replace your live tile with it.

Whenever this scheduled time is met, the Windows Phone 7 operating system goes and fetches a new tile from the URL. It must complete this request in under 15 seconds (i.e. your website/web service must reply in a timely manner).

The major problem with the above is two fold. Firstly the tile will not update until the first time the schedule time is hit – and secondly because this minimum time is 1 hour. What this means is that when your user turns on a live tile functionality in your app, nothing happens – its that simple. Nothing will happen until this first hour has rolled by. This is not good application behaviour from your users’ point of view, and you may even get some bad ratings on the marketplace because your users have complained that your live tile functionality doesn’t work! Don’t even get me started on how you are meant to debug this when your application functionality isn’t working properly.

The current state of affairs for live tile “toast” notifications

There is a second way to update a Windows Phone 7 device’s live tile and it’s by using a “Toast” notification.

This allows for the following functionality:

The Windows Phone 7 application opens a “toast” channel with Microsoft’s Windows Live service. This gives the phone a Windows Live web service Url that is the equivalent of the device’s phone number.

The Windows Phone 7 application can then upload this “Phone Home” Url to a web service that the developer of the application has written. This requires a web server and a custom web service that can store this Url for later use.

Whenever your web service wants to update a user’s Live Tile, it can send a request containing a bunch of xml data to the users phone using this Windows Live web service Url telling it to update and where to grab the live tile image from.

The problem with this is that there are quite a few moving parts and this involves going to a lot of effort just to update the live tile right this very second as it requires you to setup a web service that stores and then bounces back an update to your phone.

What if we could just remove the web service altogether?

The way to get around this problem, we have to a take a new approach. An approach that is a bit of a hybrid solution containing both methods from above, except we fake a few things on the user’s device.

We take the best parts from both, and create a toast channel, send a live tile update from the phone itself, and then start a schedule for later updates.

The new flow for this operation becomes:

The Windows Phone 7 application opens a “toast” channel with the Microsoft Windows Live web service.

The Phone sends an Http toast update notification to itself containing the Url that the application wants to be downloaded from, in turn making the user’s phone update the live tile “right now”.

Close the toast channel and start a schedule for the same Url that the application sent itself so that on the schedule the users phone will update the tile again.

The code

Below is a class that handles both of these situations, and allows you to simply update the tile, or update it and start a new schedule.

How to use it

The code can be used one of two ways. One to simply do an update using an image Url that you supply, the other to update the tile AND then start a schedule – but this time using the scheduled tile Uri for the first fetch.