我的程序里的后台agent应该每30s访问一次twitter timeline,然后把最顶端的数据内容获取,显示到tile上,但是这个tile只能在启动agent的时候更新一次,之后就再不会更新了,怎么回事?- protected override void OnInvoke(ScheduledTask task)
- {
- ShellToast popupMessage = new ShellToast()
- {
- Title = "My First Agent",
- Content = "Background Task Launched",
- };
- WebClient twitter = new WebClient();
- twitter.DownloadStringCompleted += new DownloadStringCompletedEventHandler(twitter_DownloadStringCompleted);
- twitter.DownloadStringAsync(new Uri("http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=dnivra26"));
- popupMessage.Show();
- }
- private void twitter_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
- {
- if (e.Error != null)
- return;
- XElement xmlTweets = XElement.Parse(e.Result);
- var message2 = (from tweet in xmlTweets.Descendants("status")
- select tweet.Element("text").Value).FirstOrDefault();
- UpdateAppTile(DateTime.Now.ToString() + message2.ToString());
- }
- private void UpdateAppTile(string message)
- {
- ShellTile appTile = ShellTile.ActiveTiles.First();
- if (appTile != null)
- {
- StandardTileData tileData = new StandardTileData
- {
- BackContent = message
- };
- appTile.Update(tileData);
- //NotifyComplete();
- }
- }
复制代码 |
|