Windows 8 Live Tile Background Agent Using C#
Asked Answered
E

2

3

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?

Epileptic answered 23/9, 2012 at 4:56 Comment(0)
V
3

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);
    }
View answered 5/12, 2012 at 11:39 Comment(0)
D
1

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.

Diphyllous answered 23/9, 2012 at 6:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.