我有一个静态类,它返回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客户端实例为每个请求提供服务:/
应用程序同时获得多个请求。
答案 0 :(得分:-4)
试试这个
public static class WebAccess
{
WebClient instance;
public static WebClient GetWebClient()
{
if (instance == null)
instance = new WebClient();
return instance;
}
}
那么你只有一个WebClient类的实例