gpt4 book ai didi

c# - WebClient异常,不支持并发I/O操作

转载 作者:太空宇宙 更新时间:2023-11-03 17:06:47 25 4
gpt4 key购买 nike

我有一个返回 webclient 新实例的静态类

public static class WebAccess
{
public static WebClient GetWebClient()
{
return new WebClient();
}
}

然后我就用这个类来打页面了

WebAccess.GetWebClient().DownloadString(new Uri("http://" + WLCDomainUrl + ConfigurationManager.AppSettings["urlClearCache"].ToString() + "/?id=" + Request.QueryString["id"] + "&Type=RC"));

我不想捕捉响应

但大多数时候它会抛出异常

WebClient does not support concurrent I/O operations.

Stack Trace:

at System.Net.WebClient.ClearWebClientState()
at System.Net.WebClient.DownloadString(Uri address)
at UpdateCache.ProcessLocationCacheRequest(String locId, Boolean isChain) in

WebClient does not support concurrent I/O operations.

Stack Trace:

at System.Net.WebClient.ClearWebClientState()
at System.Net.WebClient.UploadString(Uri address, String method, String data)
at System.Net.WebClient.UploadString(String address, String data)
at CacheClassLibrary.ServerClass.APIServer.Create(String Id, String MobileWLCUrl) in

有什么帮助吗?我无法想象它是我们的,因为我正在为每个请求提供新的 Web 客户端实例:/

应用程序同时收到多个请求。

最佳答案

试试这个

public static class WebAccess
{
WebClient instance;
public static WebClient GetWebClient()
{
if (instance == null)
instance = new WebClient();

return instance;
}
}

那么你只有一个 WebClient 类的实例

关于c# - WebClient异常,不支持并发I/O操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10800253/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com