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

查看:82
本文介绍了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手机上发生。我有一个Web客户端,一遍又一遍地触发,然后从完成的事件中再次触发它。这是因为仍然存在一些过时的连接而发生的吗?有没有办法防止这种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.

我如何确定在触发完成事件时,客户端不再是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 为true。

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抛出 WebClient不支持并发I / O操作。

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

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