i have asp.net application uses component in class library assembly make web service calls. component uses thread pool or sort of home brewed threading solution spawn background threads in synchronous web service calls made.
a logging component used in asp.net application , helper classes component calls background threads spawned when service calls.
in asp.net httpmodule creates logging context object , stores in httpcontext.current.items collection. helper classes used in asp.net application , in helper classes fetch logging context object httpcontext.current.items when message needs logged in order decorate logged message information puts logged message context.
when helper classes called directly asp.net, httpcontext.current available.
when helper classes called background threads created component, httpcontext.current null , there no logging context available them when messages logged; logged messages useless.
i don't have control on component creates threads making service calls. if did, arrange logging context obect copied , passed child thread.
my logging context object cannot static, because overwritten concurrent asp.net request threads , bad.
the members of logging context object (simple int/string properties) marked threadstatic, work, , not need use httpcontext.current.items anymore.
what need make .net runtime copy object (or pass reference; either do) , makes available child threads automatically.
i wondering whether add <system.threading> element web.config , nominate helper class creating threads can web requests in %lt;system.net>
i wondered whether mark logging context object attribute causes copied automatically.
i looked log4nets logicalthreadcontext, tried it, didn't work. think that's passing logging context information across processes or appdomain boundaries.
what mechanism log4net's logicalthreadcontext used behind scenes? system.runtime.remoting? deprecated now?
my environment .net 4, maybe parallel extensions or enhancements threading in .net 4 possible.
anyone idea if @ possible? i'm beginning think not.
- update *
i have had following:
task<ienumerable<account>> accountstask = task<ienumerable<account>>.factory.startnew ( instrumentationcontext => { var parentcontext = instrumentationcontext site.instrumentation.instrumentationcontext; if (site.instrumentation.instrumentationcontext.current == null && parentcontext != null) site.instrumentation.instrumentationcontext.current = parentcontext; return getaccounts(); }, site.instrumentation.instrumentationcontext.current );
where getaccounts() method calls on class in turn depends on site.instrumentation.instrumentationcontext.current
the problem is, rather not have change code explicitly pass in , set state object in child thread - want .net framework me automatically, code (above) creates task none wiser , not have changed.
if no-one else contributes alternatives, jon gets green tick figured realistic choice albeit tasks not threads.
if understand correctly need pass object thread signature what's wrong parameterized thread start ??
static void main(string[] args) { object j = new object(); thread t = new thread(()=>childthread(j)); t.start(); } private static void childthread(object someobject) { // work }
Comments
Post a Comment