C# ThreadPool对象中没有足够的可用线程来完成该操作
我对一个程序有一个问题,该程序在VisualStudio2003开发的循环中调用相同的web服务。我不断地发现这个错误:C# ThreadPool对象中没有足够的可用线程来完成该操作,c#,.net,web-services,threadpool,C#,.net,Web Services,Threadpool,我对一个程序有一个问题,该程序在VisualStudio2003开发的循环中调用相同的web服务。我不断地发现这个错误: Unable to make web service call. Ceasing processing. Message:The request was aborted: The request was canceled. System.Net.WebException: The request was aborted: The request was ca
Unable to make web service call. Ceasing processing. Message:The request was aborted: The request was canceled.
System.Net.WebException: The request was aborted: The request was canceled. ---> System.InvalidOperationException: There were not enough free threads in the ThreadPool object to complete the operation.
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.BeginGetResponse(AsyncCallback callback, Object state)
at System.Net.HttpWebRequest.GetResponse()
at System.Net.WebClient.OpenRead(String address)
OpenRead(stringaddress)
方法中的地址是有效的-我可以调试、获取地址并在浏览器中查看wsdl
我不知道如何避免这个错误——我的方法每次打开流时都会关闭它。然而,由于错误出现在OpenRead()
有没有办法清空线程池,重新开始?我尝试重新启动运行我的应用程序和托管web服务的机器,但没有成功。我还尝试将machine.config文件中的最大工作线程数增加到75,但也没有成功
我知道这个应用程序一般都能工作,因为我让它在另外两个配置完全相同的环境中运行
下面是调用web服务的循环的一部分
try
{
returnValue = WebServiceProxy.CallWebService(
transaction.WebServiceURL, transaction.WebServiceName,
transaction.Request.MethodName, args);
}
调用web服务的代理类是静态类:
public static object CallWebService(string url, string serviceName,
string methodName, object[] args)
{
//Connect to web service and retrieve WSDL
Stream stream = client.OpenRead(url + "?wsdl");
ServiceDescription description = ServiceDescription.Read(stream);
stream.Close();
看起来像是来自非托管资源的内存泄漏。请显示调用(循环)代码。注意:如果您有非托管资源并且正在调试-如果程序没有自然终止,即调试终止它或您点击停止,非托管资源将不会被释放,也不会让它们的
最终
块长时间运行。调试时,我在另一个具有相同配置的环境中进行调试。其中一台生产服务器抛出了此错误。代理调用是异步进行的还是阻塞的?如果是这样的话,这种情况发生在什么水平上?您可能正在打开流“n”次。尽管您正在关闭流,“n”个线程可能尚未到达该行-在线程池耗尽之前,它们正在运行此异常。