c# - Associate data with a thread: How do you do that? -
while writing aysnc controllers in asp.net mvc2, ran against situation had call asyncmanager.sync
. got me wondering:
when retrieve httpcontext.current
, what's going on? how asp.net know httpcontext
i'm after? how current context associated thread, , how retrieved?
thread scoped storage used, called thread local storage.
this mechanism allows data affinitized thread i.e. thread allocates data sees data. useful creating called ambient programming models such httpcontext.current , transactionscope. mechanism allows data accessible @ time on executing thread without having "tramp" data through method parameters instance. it's elegant solution context\orthogonal problems.
there number of ways of using tls including threadstaticattribute , thread.setdata\getdata.
Comments
Post a Comment