I have a client which makes a limited number of concurrent web requests. I use WebClient for this purpose. I currently have a pool of WebClient-s which I create once and use whichever one is idle.
This approach is becoming a little cumbersome though, and I'm wondering if there is any benefit to having a collection of pre-constructed WebClient instances, or if creating them on the fly wouldn't be too much trouble?
Why on earth would you have a pool of WebClients in the first place? They are tiny, cheap objects. Did you determine by measuring that this is needed and beneficial? I assume not?
Object instantiation is almost always cheap. HTTP connections are not expensive, either. A WebClient pool is premature optimization. There is no need for it - feel free to create as many as you want.
According to Reflector all that the constructor of WebClient does is this:
public WebClient()
{
this.m_Encoding = Encoding.Default;
this.m_ContentLength = -1L;
}
So no you have not much benefit of having a pool.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With