C# asynchronous method - help needed

后端 未结 3 1368
逝去的感伤
逝去的感伤 2021-01-17 03:17

I have an asynchronous method that consumes a Web API action. It appears to be stuck in a loop. My reasoning for this is because if I put a break point on line 1 of the catc

3条回答
  •  囚心锁ツ
    2021-01-17 03:53

    Are you working in a external library? If so try adding ConfigureAwait(false);

    var response = await _client.GetAsync(string.Format("{0}/api/document", _baseURI))
                                .ConfigureAwait(false);
    

    Its to do with telling await not to capture the current context. Calling ConfigureAwait will ensure the rest of the method is executed using the ThreadPool. Some good reading on the subject can be found here on Stephen Cleary's blog.

提交回复
热议问题