Tutorial :Are threads reused between requests in ASP.Net?



Question:

I'm just wondering if the same thread is used for each session, or if its dangerous to count on a particular thread between requests. What I'm getting at, is can I use thread static storage?


Solution:1

The short answer is yes. The thread used for a request is returned to the thread pool and can be used to service other requests. They are NOT session specific, and to answer your second question, you should never count on a particular thread being available for subsequent requests on a particular session. Because of this, it is a very bad idea to use thread static variables in ASP.Net.


Solution:2

What I'm getting at, is can I use thread static storage?

No. Use the Application/Cache or Session stores instead.


Solution:3

What I'm getting at, is can I use thread static storage?

Or if you only want the data to stay around for the lifetime of a single request, you can store it in HttpContext.Current.Items


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »