与 this question 类似, 是否可以实例化一个客户端并保留它,或者我是否需要为每次调用(或批量调用)创建一个新实例?
最佳答案
如有疑问,可能的话,look at the source code .
从简短的角度来看,保持单个实例似乎是可以接受的,甚至是更好的方法,因为它主要负责执行 IRestRequest
请求。
我曾经对关于 HttpClient
的相同问题有疑问并找到了 the following :
The default HttpClient is the simplest way in which you can start sending requests. A single HttpClient can be used to send as many HTTP requests as you want concurrently so in many scenarios you can just create one HttpClient and then use that for all your requests.
如果需要并发,请查看源代码以查看是否存在任何陷阱。您始终可以默认返回 HttpClient
,它是 .NET 4.5 以来 BCL 的一部分(并且可以通过 .NET 4.0 上的 NuGet 安装)
关于c# - 为 RestSharp 客户端维护单个实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26413129/