Working with WebClient object and Timeout

3 באפריל 2012

no comments

Hi,The WebClient object in .NET doesn't expose the request TimeOut property.In case you decided to use this object it is better to inherit from it and expose the TimeOut property. 
Example:

public class SearchWebClient : WebClient
{
   public SearchWebClient()
   {
        Timeout = 2000;
    }

    public SearchWebClient(int timeout)
   {
      Timeout = timeout;
    }


///<summary>
/// Request timeout in milliseconds 
///</summary>
public int Timeout { get; set; }
protected override WebRequest GetWebRequest(Uri address)
{
   WebRequest result = base.GetWebRequest(address);
   if(result != null) 
   {
      result.Timeout = Timeout;
    }
    
     return result;
}}
Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*