我試圖從我的Twitter帳戶中獲取推文,並在我的外殼磁貼上顯示最多的推文。所以我創建了一個後臺代理(定期任務)來完成它。每隔30分鐘,後臺代理應該訪問我的Twitter時間表並獲取我最頂級的推文並將其顯示在平鋪中。問題是我的瓷磚只有一次更新,即當我啓動代理時,之後它不會更新。Shelltile在Windows Phone 7.1中未正確更新
這裏是我的後臺代理代碼:
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();
}
}
我能夠獲得最高鳴叫一次。
我是慢應答。 :D – BigL 2012-01-09 21:20:17