Cannot propagate AspNetSynchronizationContext to TPL task

djsadi

New Member
I've read a number of articles that in order to preserve HttpContext.Current in versions prior to 4.5, we should pass on handling thread's SynchornizationContext.
Here is a code I am attempting to execute:\[code\]TaskScheduler taskScheduler = TaskScheduler.FromCurrentSynchronizationContext();Task.Factory.StartNew(() => HandleInquiry(currentInquiry, request), CancellationToken.None, TaskCreationOptions.None, taskScheduler)\[/code\]When I debug through this code, I can confirm that the taskScheduler contains AspNetSynchronizationContext prior to Task scheduling. However, inside the HandleInquiry method (inside a Task) the SynchronizationContext.Current is null and HttpContext.Current is also null. I am sure I am missing something obvious.
 
Back
Top