3
votes

I am trying to update a live tile every so often on Windows 8 and need to do this even if the app itself isn't running. None of the notification options listed on this MSDN page are suitable, I want to poll system information like CPU temp etc which doesn't suit the styles of notifications listed.

I've looked elsewhere on StackOverflow and seen similar questions but for Windows Phone 7 using background workers. Using a background worker seems like the right answer for me as well. However, tutorials like the previous one focus on Windows Phone 7 where things are a bit different, the Windows Store templates in Visual Studio 2012 Ultimate don't have C# templates for Scheduled Task Agents for example.

So my question is how can we set up background workers for Windows 8 apps to preform live tile updates when the application itself isn't running?

2

2 Answers

3
votes

U can read about Background Tasks here; read about TimeTrigger here, and in method OnCompleted at operation background task, we can set LiveTile

    void OnCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
    { 
      var tile = CreateNotification(String.Format(@"<tile>
      <visual>
        <binding template=""TileSquareText04"">
          <text id=""1"">{0}</text>
          <text id=""2""></text>
        </binding> 
        <binding template=""TileSquareText02"">
          <text id=""1"">{0}</text>
          <text id=""2""></text>
        </binding>  
      </visual>
    </tile>", DateTime.Now.ToString("hh:mm:ss")));
     TileUpdateManager.CreateTileUpdaterForApplication().Update(tile);
     }
    private TileNotification CreateNotification(string xml)
    {
        var xmlDocument = new XmlDocument();
        xmlDocument.LoadXml(xml);
        return new TileNotification(xmlDocument);
    }
1
votes

Check out the whitepaper: Introduction to Background Tasks; between that and what you've already learned and researched about tiles, you should be able to pull something together.