Deadclock on calling async methond

Issue:

HttpClient.GetAsync(…) never returns when using await/async

Related Posts:

http://stackoverflow.com/questions/9895048/async-call-with-await-in-httpclient-never-returns

http://stackoverflow.com/questions/10343632/httpclient-getasync-never-returns-when-using-await-async/10351400#10351400

Solution:

Quick fix from here. Instead of writing:

Task tsk = AsyncOperation();
tsk.Wait();
Try:

Task.Run(() => AsyncOperation()).Wait();
Or if you need a result:

var result = Task.Run(() => AsyncOperation()).Result;

posted @ 2016-09-29 11:11  Researcher  阅读(133)  评论(0编辑  收藏  举报