From: http://www.cnblogs.com/xunziji/archive/2011/01/24/1943092.html
No problems were found during cross-Origin data request using methods such as downloaddata and downloadfileasync of WebClient today. After half a day, I was taken aback when I checked the error log and found many error messages about WebClient does not support concurrent I/O operations. After carefully viewing the stack of the error information, run the error method and URL copy in the browser and enter the corresponding parameters. However, it is found that the method can be called, which is very depressing, it seems that this error does not appear every call, and it is more difficult to troubleshoot.
Finally, Google spent half a day reading a lot of information and found that as long as the error message contains information about does not support concurrent I/O operations, it is generated by calling an instance in multiple places at the same time. In plain words, it is caused by concurrency. The following is an explanation from 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 shoshould work just fine.
Finally, paste your ownCode:
Private Static WebClient WC;
Static Test ()
{
WC = new WebClient ();
WC. headers ["User-Agent"] = config. Host + "|" + servicekey;
}
The original WebClient is static and Global. Therefore, the above error is reported when WC is used to operate data concurrently.
Solution: A New WebClient instance is added to each WebClient to prevent concurrency. At the same time, the does not support concurrent I/O operations error method is generally caused by concurrency. For the solution, refer to the previous sentence.