/// <summary> /// Agent that runs a scheduled task /// </summary> /// <param name="task"> /// The invoked task /// </param> /// <remarks> /// This method is called when a periodic or resource intensive task is invoked /// </remarks> protected override void OnInvoke(ScheduledTask task) { OutputAvailableMemory("Start"); try { DateTime newsDate = (DateTime)IsolatedStorageSettings.ApplicationSettings["NewsDate"]; NewsRepository repository = new NewsRepository(); OutputAvailableMemory("Repo erzeugt"); repository.GetNewNewsCountAsync(newsDate).ContinueWith(t => { if (t.Status == TaskStatus.RanToCompletion) { ShellTile appTile = ShellTile.ActiveTiles.First(); appTile.Update(new StandardTileData() { Count = t.Result }); } if (task is ResourceIntensiveTask) { // Bei einem RessourceIntensiveTask alte Nachrichten löschen DateTime timeLimit = DateTime.Now.AddMonths(-1); repository.DeleteNewsOlderThan(timeLimit); } OutputAvailableMemory("Ende"); NotifyComplete(); }); } catch (Exception ex) { // Nichts machen NotifyComplete(); } }