WebClient does not support concurrent I/O operations 错误的解决办法

贴出一下自己的出错代码:

WebClient client = new WebClient();          // 这句话应该放到for循环里.
for (int i = 0; i < mEmotionUrl.Count; i++)
 {
       string a = mEmotionUrl[i].Url;
       client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted);
       client.OpenReadAsync(new Uri(a, UriKind.RelativeOrAbsolute));
 }

最后,google 了半天,并看了许多资料,发现 只要错误信息含有 does not support concurrent I/O operations 信息的,都是由 一个实例同时在多个地方调用产生的,通俗易懂的说,就是并发引起的。下面摘录一句google到得解释:


I don't think you can use a single WebClient instance to execute several
HTTP requests at the same time. Try to create a WebClient instance per request,
that should work just fine.


原来自己的 client 只有一个实例引发多个调用,就报了上述错误

解决办法 :每个使用到 WebClient 的地方,都 new 一个 WebClient 实例,防止出现并发。同时 does not support concurrent I/O operations 错误的方法,一般也是由于 并发引起的,解决方法请参照上一句。

转载于:https://www.cnblogs.com/navigator/archive/2011/05/30/2917702.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值