Using PerThreadLifetimeManager in ThreadPool and ASP.Net

May 25, 2009 at 1:19 AM

Is it safe to use PerThreadLifetimeManager in ASP.Net given:

  1. states that ThreadPool does not clear the data in thread local storage,
  2. ASP.Net uses the thread pool

Any alternatives if this is not safe?




May 25, 2009 at 4:11 AM

Depending on what you're doing, in general the answer is no. ASP.NET manages threads, you don't. Your best option would be to write a small custom PerRequestLifetimeManager that stores the items in HttpContext.Current.Items instead, which is probably what you want. If that's not what you want, could you provide more information on what you are trying to do?