Reputation: 25927
I have the following piece of code (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?
Upvotes: 0
Views: 179
Reputation: 38079
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.
Mitigate this by awaiting the client.GetAsync()
and use ConfigureAwait
where possible to minimize chances of deadlocks:
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)
Upvotes: 2