c# - ThreadStaticAttribute in ASP.NET -
i have component needs store static
values fore each thread. it's general component can used in many scenarios , not in asp.net.
i thinking use [threadstatic]
attribute achieve goal. supposing work fine in asp.net scenarios, because assuming every request called in own thread.
after research found this blog post scott hanselman saying careful when using [threadstatic]
in asp.net.
however of comments (below post) not agree scott wrote, saying request run in 1 thread , thread not used request @ same time. that's believe love have opinion experts in here.
nope, scott right: request doesn't have run on single thread entire duration. asp.net thread-agile in respect. there few points switch can happen, can happen. (i've tested myself.)
you may wish read this blog post , this spring forum thread more details.
basically should find different way of capturing context. relevant bit point of view @ end of blog post:
this major pita, because far can see mean persistence option 'threadstatic'esque behavior in asp.net use httpcontext. business objects, either you're stuck if(httpcontext.current!=null) , system.web reference (yuck) or you've got come kind of provider model static persistence, need setting prior point of these singletons accessed. double yuck.
Comments
Post a Comment