Deadlock reading async response content from async DelegatingHandler in webapi

与世无争的帅哥 提交于 2019-12-06 10:18:28

Peter, first of all, you are right about the cause of this deadlock. Try to use async/await all the way down. In other words, do not block on async code. Another thing you should do is using the .ConfigureAwait(false):

    var response = await base.SendAsync(request, cancellationToken).ConfigureAwait(false);

    string content = "";
    if (response.Content != null)
    {
        content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); 
    }

More info you can find at this link

If none of the above work, please provide a complete example, ok?

Hope this helps!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!