Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Starting two WebClient.UploadStringAsync calls subsequently

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

"WebClient does not support concurrent I/O operations"

Apparently, this is not supported.

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?

like image 512
Dimitri C. Avatar asked Dec 04 '25 10:12

Dimitri C.


1 Answers

You need to use multiple instances of 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);
like image 94
AnthonyWJones Avatar answered Dec 07 '25 11:12

AnthonyWJones



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!