What is the overhead of creating a new HttpClient per call in a WebAPI client?

前端 未结 7 1855
心在旅途
心在旅途 2020-11-22 07:26

What should be the HttpClient lifetime of a WebAPI client?
Is it better to have one instance of the HttpClient for multiple calls?

Wh

相关标签:
7条回答
  • 2020-11-22 07:50

    You may also want to refer to this blog post by Simon Timms: https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/

    But HttpClient is different. Although it implements the IDisposable interface it is actually a shared object. This means that under the covers it is reentrant) and thread safe. Instead of creating a new instance of HttpClient for each execution you should share a single instance of HttpClient for the entire lifetime of the application. Let’s look at why.

    0 讨论(0)
提交回复
热议问题