/// <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) { //TODO: Add code to perform your task in background var searcher = new Searcher(); searcher.Search(task.Description, (tweets) => { Microsoft.Phone.Shell.ShellToast toast = new Microsoft.Phone.Shell.ShellToast(); toast.Title = "New Tweets"; toast.Content = string.Format("{0} new tweets for {1}", tweets.Count(), task.Description); toast.Show(); NotifyComplete(); }); }
public TwitterSearchViewModel() { this.searcher = new Searcher(); this.SearchCommand = new TwitterSearchCommand(() => { this.searcher.Search(this.SearchQuery, (tweets) => { this.Tweets = tweets; this.RaisePropertyChanged("Tweets"); }); }); this.BackgroundTaskComand = new GalaSoft.MvvmLight.Command.RelayCommand(() => { PeriodicTask task = new PeriodicTask("TwitterSearch"); task.Description = this.SearchQuery; task.ExpirationTime = DateTime.Now.AddDays(1); ScheduledActionService.Add(task); }); }