Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are threads reused between requests in ASP.Net?

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?

like image 635
user18931 Avatar asked Oct 15 '08 14:10

user18931


3 Answers

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.

like image 180
Kilhoffer Avatar answered Nov 08 '22 06:11

Kilhoffer


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

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

like image 41
Oli Avatar answered Nov 08 '22 07:11

Oli


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

like image 40
mike nelson Avatar answered Nov 08 '22 06:11

mike nelson