Does every 'HttpRequest' get its own thread in ASP.NET?

Dan Esparza picture Dan Esparza · Sep 13, 2009 · Viewed 7.6k times · Source

In ASP.NET, does every HttpRequest get its own thread?

Update - To clarify, I'm asking specifically about incoming requests.

Answer

Rex M picture Rex M · Sep 13, 2009

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.