WebClient does not support concurrent I/O operations error Solution

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.