views:

344

answers:

3

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?

+7  A: 

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.

Kilhoffer
+1  A: 

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

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

Oli
A: 

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

mike nelson