本文介绍了随后启动两个WebClient.UploadStringAsync调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在两次调用WebClient.UploadStringAsync时,不等待WebClient.UploadStringCompleted事件,抛出以下异常:

When calling WebClient.UploadStringAsync twice, without waiting for the WebClient.UploadStringCompleted event, the following exception is thrown:

WebClient不支持并发I / O操作

"WebClient does not support concurrent I/O operations"

显然,这不受支持。

想要启动多个HTTP POST请求而不必等待先前的响应到达的原因是因为性能;我想避免往返延误。是否有针对此限制的解决方法?

The reason for wanting to start multiple HTTP POST requests without having to wait for the previous response to arrive is because of performance; I want to avoid the round trip delay. Is there a workaround for this limitation?

推荐答案

您需要使用 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);

这篇关于随后启动两个WebClient.UploadStringAsync调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 07:35