ThreadStatic is not recommended in ASP.NET - but only within the request pipeline (hence the session-per-request model that uses HttpContext.Items that Jose already mentioned). If you're creating your own background thread, then this thread will not be randomly created and reallocated within the pipeline - so ThreadStatic within that thread should be fine. You would want to be careful how you were storing your reference *to* that background thread though! James
2009/9/1 Lachlan Roche <[email protected]> > > ThreadStatic is not recommended in ASP.NET, use HttpContext.Items instead. > > A discussion on why ThreadStatic is not safe: > http://stackoverflow.com/questions/273301/callcontext-vs-threadstatic > > A example of session per request in ASP.NET: > http://ayende.com/Blog/archive/2009/08/05/do-you-need-a-framework.aspx > > > > On Tue, Sep 1, 2009 at 8:41 AM, James Crowley<[email protected]> > wrote: > > If it's in a different thread, then you'll need to store another session > of > > nHibernate in there. > > you could look at using a [ThreadStatic] attribute to store your session > > (you get an instance per thread). very simplistic example below... > > [ThreadStatic] > > static ISession _session; > > void MyMethod() { > > if (_session == null) > > /// start session > > // use session here > > } > > hope that helps > > > > 2009/8/28 Jose Samonte <[email protected]> > >> > >> Good day! > >> I'm doing a session-per-request in my ASP.NET application, but I also > need > >> to start a background thread on application start that also uses > NHibernate. > >> How can I do this? > >> > >> Thanks, > >> Joey > >> > > > > > > > > -- > > James Crowley > > Managing Director > > Developer Fusion - Connecting developers worldwide > > > > Developer Fusion Ltd | 58 Sandringham Close | Enfield, EN1 3JH > > mob: 07986 624128 web: http://www.developerfusion.com/ > > > > > > > > > > > -- > lachlan > > > > -- James Crowley Managing Director Developer Fusion - Connecting developers worldwide Developer Fusion Ltd | 58 Sandringham Close | Enfield, EN1 3JH mob: 07986 624128 web: http://www.developerfusion.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~----------~----~----~----~------~----~------~--~---
