在两次调用WebClient.UploadStringAsync时,不等待WebClient.UploadStringCompleted事件,抛出以下异常:
“WebClient不支持并发I / O操作”
显然,这不受支持。
想要启动多个HTTP POST请求而不必等待先前响应到达的原因是因为性能;我想避免往返延误。是否有针对此限制的解决方法?
答案 0 :(得分:8)
您需要使用WebClient
的多个实例。
var wc1 = new WebClient();
wc1.UploadStringCompleted += (s, args) => {
// do stuff when first upload completes
}
wc1.UploadString(uri1,str1);
var wc2 = new WebClient();
wc2.UploadStringCompleted += (s, args) => {
// do stuff when second upload completes
// might happen before first has completed
}
wc2.UploadString(uri2,str2);