WebClient超时设置问题
大家好我们都知道,WebClient不能直接设置超时,但我们可以通过定义一个类,继承WebClient,然后重写GetWebRequest方法,如下:
public class ProTimerWebClient : WebClient {
private int timeOut;
public ProTimerWebClient(int timeOut) {
this.timeOut = timeOut;
}
protected override WebRequest GetWebRequest(Uri address)
{
var request= (HttpWebRequest ) base.GetWebRequest(address);
request.Timeout = timeOut;
request.ReadWriteTimeout = timeOut;
return request;
}
}
但是,当我做如下调用的时候,却抛出空引用异常!
using (var client = new ProTimerWebClient(2000))
{
client.UploadValuesCompleted += new UploadValuesCompletedEventHandler(client_UploadValuesCompleted);
client.UploadValuesAsync(new Uri(URL), "POST", parameter,null);
}
哪位朋友能指点一二,不胜感激! --------------------编程问答-------------------- 不懂帮顶 --------------------编程问答-------------------- - -!兄弟 我正愁怎么取消 超时来着。
我一次处理的数据量太大,导致页面加载超时了。但是又不能分段处理。
补充:.NET技术 , C#