public static void UpdateLiveTiles() { Settings settings = new Settings(); var tileXml = TileCreator.GenerateTile(settings.AppLanguage, DateTimeOffset.Now, settings.TileTier); Debug.WriteLine("Tile XML generated"); var tileNotification = new TileNotification(tileXml); var tileUpdaterApp = TileUpdateManager.CreateTileUpdaterForApplication(); tileUpdaterApp.Update(tileNotification); Debug.WriteLine("Primary tile updated"); GC.Collect(); // a simple check that should avoid the exception if (SecondaryTile.Exists(SecondaryAppTileId)) { try { tileNotification = new TileNotification(tileXml); var tileUpdaterSecondary = TileUpdateManager.CreateTileUpdaterForSecondaryTile(SecondaryAppTileId); tileUpdaterSecondary.Update(tileNotification); Debug.WriteLine("Secondary tile updated"); } catch (Exception ex) { Debug.WriteLine("Secondary tile update failure. Non-critical - {0}", ex); } } }
private static void ScheduleTileUpdate(DateTimeOffset dtoTime, Settings settings) { if (dtoTime < DateTimeOffset.Now) { return; } var tileXml = TileCreator.GenerateTile(settings.AppLanguage, dtoTime, settings.TileTier); Debug.WriteLine("Tile XML generated"); ScheduledTileNotification stn = new ScheduledTileNotification(tileXml, dtoTime); // assign a tag for better id stn.Tag = dtoTime.ToString("yyMMdd hhmm", CultureInfo.InvariantCulture); Debug.WriteLine("Scheduling notification {0}", stn.Tag); var tileUpdaterApp = TileUpdateManager.CreateTileUpdaterForApplication(); tileUpdaterApp.AddToSchedule(stn); // secondary if (SecondaryTile.Exists(SecondaryAppTileId)) { try { ScheduledTileNotification stn2 = new ScheduledTileNotification(tileXml, dtoTime); // assign a tag for better id stn.Tag = dtoTime.ToString("yyMMdd hhmm", CultureInfo.InvariantCulture); Debug.WriteLine("Scheduling notification {0}", stn.Tag); var tileUpdaterApp2 = TileUpdateManager.CreateTileUpdaterForSecondaryTile(SecondaryAppTileId); tileUpdaterApp2.AddToSchedule(stn2); } catch { ; } } }