PRB: System.InvalidOperationException Error When You Use HttpWebRequest and HttpWebResponse Classes in Application with Thread Pool (815637)
The information in this article applies to:
- Microsoft ASP.NET (included with the .NET Framework) 1.0
- Microsoft ASP.NET (included with the .NET Framework 1.1)
SYMPTOMSWhen you use the System.Net.HttpWebRequest and
the System.Net.HttpWebResponse classes in an application that uses a thread pool,
you may receive the following error message: System.InvalidOperationException: There were not enough free
threads in the ThreadPool object to complete the
operation CAUSEThe System.Net.HttpWebRequest and the System.Net.HttpWebResponse
classes always use asynchronous methods to complete a request. When the
asynchronous request is made, ASP.NET uses a new thread from the ThreadPool object.
When ASP.NET does not find a thread, the System.Net.HttpWebRequest class returns the error message
instead of queuing the request.WORKAROUNDTo work around this problem, use one of
the following methods: - Use a Try-Catch block in the code to catch the
exception and to handle it appropriately.
- Implement a queuing mechanism to keep the exception
from occurring.
- If you are using ASP.NET in Microsoft Internet Information Services 5.0 or later, reconfigure the thread pool size in the Machine.config
file. To do this, follow these steps:
- Open the Machine.config file from the %Systemroot%\Microsoft.NET\Framework\Version\CONFIG folder.
- In the <processModel> section of the
Machine.config file, configure the value of the maxWorkerThreads
and the maxIoThreads attributes to the maximum number of threads
for the process for each CPU. For example, if this value is 25 on a
single-processor server, ASP.NET uses the run-time application programming interfaces (APIs) to set the process limit
to 25. On a two-processor server, the limit is set to 50.
Note Monitor the CPU usage when you increase a thread pool to
maintain the limits. - Save the changes to the Machine.config file.
STATUS This
behavior is by design.REFERENCESFor more information, visit the following Microsoft Web
sites:
Modification Type: | Major | Last Reviewed: | 5/15/2003 |
---|
Keywords: | kbNameSpace kbweb kbXML kbWNet kberrmsg kbConfig kbDev kbThread kbprb KB815637 kbAudDeveloper |
---|
|