In ASP.NET, does every HttpRequest
get its own thread?
Update - To clarify, I'm asking specifically about incoming requests.
The “hard” limit on the max number of threads in the IIS thread pool. This limit can be set to a value between 64 and 256, so you cannot have more than 256 IIS threads in the pool regardless of settings.
So as in our case default threads are 12 which means the number of threads in the thread pool is 12 and when the 13th request comes it will look for a free thread and if all the threads are busy then it will spawn a new thread but will wait for some 0.5 seconds before it spawns a new thread.
HttpContext access from a background threadHttpContext isn't thread-safe. Reading or writing properties of the HttpContext outside of processing a request can result in a NullReferenceException.
To increase the value for the Threads Per Processor Limit follow these steps:In the Connections pane, select the web server, click to select Features View, and then double-click the ASP feature. Click Start, point to All Programs, click Administrative Tools, and then click Internet Information Services (IIS) Manager.
If you're referring to using the HttpRequest object for making outgoing requests from your application, no - HttpRequest runs in the current thread.
If you're referring to how IIS and ASP.NET handles threading per request, yes. Each request is run on a separate thread. However, the model is a little more complex than that - there are worker threads and I/O threads to consider. And under load, .NET will sometimes move requests from one thread to another as it sees fit. This is important to understand when dealing with things like ThreadStatic.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With