Grzenio Grzenio - 1 year ago 195
C# Question

How can I change the time limit for webClient.UploadData()?

I am using

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)

Answer Source

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

 public class WebClientEx : WebClient
     public int Timeout {get; set;}

     protected override WebRequest GetWebRequest(Uri address)
        var request = base.GetWebRequest(address);
        request.Timeout = Timeout;
        return request;


 var myClient = new WebClientEx();
 myClient.Timeout = 900000 // Daft timeout period
 myClient.UploadData(myUri, myData);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download