リスト内の2人以上のユーザーのタイムラインを取得し、日付順に並べてリストビューに表示しようとしています
現時点では、次のものがあります:-
Contacts searchTerm1 = cmbContact.SelectedItem as Contacts;
if (searchTerm1 != null)
{
contactList = GetCurrentContacts(searchTerm1.CatID);
foreach (var contact in contactList)
{
GetTweetResults(contact.Username);
foreach (var contactTweet in _contactTweets)
{
_allContactTweets.Add(contactTweet);
}
}
TweetList1.ItemsSource = _allContactTweets;
}
そして、私はつぶやきを非同期に取得しています
private void GetTweetResults(string user)
{
WebClient twitterAccess = new WebClient();
twitterAccess.DownloadStringCompleted += new DownloadStringCompletedEventHandler(twitterAccess_DownloadStringCompleted);
twitterAccess.DownloadStringAsync(new Uri("http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=" + user));
}
private void twitterAccess_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs args)
{
try
{
XElement xmlTweets = XElement.Parse(args.Result);
var contactTweets = (from tweet in xmlTweets.Descendants("status")
select new ContactTweet
{
ProfileImage =
tweet.Element("user").Element("profile_image_url").Value,
TweetText = tweet.Element("text").Value,
UserName = tweet.Element("user").Element("screen_name").Value,
Created = (tweet.Element("created_at").Value.ParseDateTime())
}).ToList();
foreach (var contactTweet in contactTweets)
{
_contactTweets.Add(contactTweet);
}
}
catch (Exception exception)
{
MessageBox.Show("Error downloading tweets - " + exception.Message);
}
}
}
今私の考えは、GetTweetResults で、twitterAccess_DownloadStringCompleted が終了するのを待ってからプロセスを続行することですが、その方法がわかりません。
これを達成する方法を誰か教えてもらえますか?
あなたの助けと時間をありがとう
アップデート
なんとかそれを下に置くことができました
WebClient twitterAccess = new WebClient();
twitterAccess.DownloadStringCompleted += new DownloadStringCompletedEventHandler(twitterAccess_DownloadStringCompleted);
twitterAccess.DownloadStringAsync(new Uri("http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=" + contactList1[0].Username));
WebClient twitterAccess2 = new WebClient();
twitterAccess2.DownloadStringCompleted += new DownloadStringCompletedEventHandler(twitterAccess_DownloadStringCompleted);
twitterAccess2.DownloadStringAsync(new Uri("http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=" + contactList1[1].Username));
ここで、contactList1 をループして WebClient を動的に生成する方法を見つける必要があります.....
更新 2
問題が解決しました
foreach (var contact in contactList)
{
WebClient twitterAccess = new WebClient();
twitterAccess.DownloadStringCompleted += new DownloadStringCompletedEventHandler(twitterAccess_DownloadStringCompleted);
twitterAccess.DownloadStringAsync(new Uri("http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=" + contact.Username));
}