[英]Async methods doesn't seem to work on Windows Phone
I have the following piece of code (WPF, Windows Phone 8.1): 我有以下代码(WPF,Windows Phone 8.1):
HttpClient client = new HttpClient();
var httpResult = client.GetAsync(feed.Url, ct);
string feedData = await httpResult.Result.Content.ReadAsStringAsync();
var sf = new SyndicationFeed();
sf.Load(feedData);
I'm trying to debug this code. 我正在尝试调试此代码。 However, after the line:
但是,在行之后:
string feedData = await httpResult.Result.Content.ReadAsStringAsync();
debugger seems to let application run on its own and never reaches the next line. 调试器似乎让应用程序自己运行,并且永远不会到达下一行。 Why is that?
这是为什么? Am I doing something wrong?
难道我做错了什么?
Depending on if you are calling result or wait on the task somewhere upstream, this can result in a deadlock as noted in Stephen Cleary's blog post . 取决于您是调用结果还是在上游某处等待任务,这可能导致死锁,如Stephen Cleary的博客文章中所述 。
Mitigate this by awaiting the client.GetAsync()
and use ConfigureAwait
where possible to minimize chances of deadlocks: 通过等待
client.GetAsync()
缓解这种情况,并在可能的情况下使用ConfigureAwait
最小化死锁的可能性:
HttpClient client = new HttpClient();
var httpResult = await client.GetAsync(feed.Url, ct).ConfigureAwait(false);
string feedData = await httpResult.Content.ReadAsStringAsync().ConfigureAwait(false);
var sf = new SyndicationFeed();
sf.Load(feedData)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.