WebClient 不支持并发 I/O 操作 [英] WebClient does not support concurrent I/O operations

查看:35
本文介绍了WebClient 不支持并发 I/O 操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 DownloadStringCompleted 事件中获取此错误?不是说完了吗?是否还有其他事件可以触发此事件?

How can I get this error from with in the DownloadStringCompleted Event? Doesn't that mean, it's finished? Is there another event I can fire this from?

我很少收到此错误,但偶尔会在我的 WP7 手机上发生.我有一个网络客户端,我一遍又一遍地触发它,然后从完成的事件中再次触发它.发生这种情况是因为仍有一些陈旧的连接打开吗?有没有办法 100% 防止这种情况发生?

I get this error extremely rarely, but once in a while it will happen on my WP7 phone. I have a web client that I fire over and over, and I fire it again from the completed event. Is this happening because there is still some stale connection open? Is there a way to prevent this 100%?

我已经检查过线程是否有机会遍历自身,但它仅在已完成的事件中被触发.

I have checked to see if there is a chance for the thread to walk over itself, but it is only fired from within the completed event.

我如何确定,当 complete 事件被触发时,客户端不再是 isBusy?一个建议是在客户端忙时添加一个线程睡眠一段时间.

How can I be sure, when the complete event is fired, the client is no longer isBusy? One suggestion was to add a while with a thread sleep while the client is busy.

一些伪代码.

var client = new WebClient("URL 1");
client.CompletedEvent += CompletedEvent;
client.downloadasync();

void CompletedEvent(){
Dosomestuff;
client.downloadasync(); //This is where we break.
}

推荐答案

WebClient 只支持单个操作,不能下载多个文件.您还没有显示您的代码,但我的猜测是您在旧请求完成之前以某种方式触发了一个新请求.我敢打赌,WebClient.IsBusy 在您尝试执行另一个提取时为真.

The WebClient only supports a single operations, it cannot download multiple files. You haven't shown your code, but my guess is that you are somehow firing a new request before the old is completed. My bet is that WebClient.IsBusy is true when you attempt to perform another fetch.

请参阅以下主题:

wb.DownloadFileAsync throw "WebClient 不支持并发 I/O 操作."例外

这篇关于WebClient 不支持并发 I/O 操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆