Aug 19, 2012 at 9:47 AM
Edited Aug 20, 2012 at 12:29 PM
What is the best practice in terms of flowing context in message handlers? I mean using
when doing Continuations.
Although using HttpContext.Current in controllers, etc is generally discouraged, it is not a decision to be taken in message handlers so controller must be free to decide to use it or not - regardless being a bad design decision.
I know that the overhead is, if we have 10 message handlers and all flow the context, all of the context must be copied to the new thread at the time of context switching (i.e. 2x10 times). And this will affect the performance although at the end of the
day before now, context switching used to do this anyway.
Brad also has a series on the topic which uses a different approach (SysnchornizationContext.Curremt.Post). Is that the de-facto approach and still valid? Reason I am asking is that Brad later blogged about overhead of creating TaskCompletionSource but this
approach creates them often.
So what is the ASP.NET team recommendation? To Use TaskScheduler.FromCurrentSynchronizationContext() (or SysnchornizationContext.Curremt.Post) or not to use? That is the question!