1
我会通过发布这是困扰代码开始:C#等待lambda函数
public async Task main()
{
Task t = func();
await t;
list.ItemsSource = jlist; //jlist previously defined
}
public async Task func()
{
TwitterService service = new TwitterService(_consumerKey, _consumerSecret);
service.AuthenticateWith(_accessToken, _accessTokenSecret);
TwitterGeoLocationSearch g = new TwitterGeoLocationSearch(40.758367, -73.982706, 25, 0);
SearchOptions s = new SearchOptions();
s.Geocode = g;
s.Q = "";
s.Count = 1;
service.Search(s, (statuses, response) => get_tweets(statuses, response));
void get_tweets(TwitterSearchResult statuses, TwitterResponse response)
{
//unimportant code
jlist.Add(info);
System.Diagnostics.Debug.WriteLine("done with get_tweets, jlist created");
}
我有与get_tweets问题(..)功能在运行中(我相信什么不同的线程)和任务t不像我在主函数中那样等待。基本上,我的问题是,list.Itemsource = jlist在get_tweets函数完成之前运行。有没有人有解决方案或正确的方向指向我?
你没有得到警告说,你的'FUNC()'异步方法不包含任何'await'声明? –
我认为您没有复制足够的代码来查看问题所在;例如,func()没有await语句,所以应该同步运行。 – antlersoft
@antlersoft不,有足够的代码。问题是他使用了一个回调方法,所以它是异步的,但它使用了一个非任务异步模型。这是根本问题。 – Servy