C# 2008
I am not sure how much work there is to inheriting from the web client class.
Currently I am using it in my project. And I can't change to anything else. The customer would like to have a timeout after a certain period of time. The web client doesn't have this.
So rather than re-invent the wheel, I am thinking of inheriting from the web client and adding this property.
Do you think this is a suitable solution? Could it mean more work just to add this. What is the easiest way to go about this?
Many thanks,
extend webclient to add a timeout property that can optionally be set in an overloaded constructor (a timeout of 0 or less means no timeout). Then override the GetWebRequest method:
protected override WebRequest GetWebRequest(Uri address)
{
var req = base.GetWebRequest(address);
var httpReq = req as HttpWebRequest;
if (httpReq != null && Timeout > 0)
{
httpReq.Timeout = Timeout;
}
return req;
}
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