views:

259

answers:

1

I am using WebClient.UploadData() to do a post on a Java server. How can I extend the time limit? (It times out every time I am trying to do some debugging)

+3  A: 

The WebClient doesn't have a timeout property however it is possible inherit from the WebClient to give access to Timeout on the internal WebRequest used:-

 public WebClientEx : WebClient
 {

     public int Timeout {get; set;}
     protected override WebRequest GetWebRequest(Uri address)
     {
        var request = base.GetWebRequest(address);
        request.Timeout = Timeout;
        return request;
     }
 }

Usage:-

 var myClient = new WebClientEx();
 myClient.Timeout = 900000 // Daft timeout period
 myClient.UploadData(myUri, myData);
AnthonyWJones