this method - doDayBegin(item.BranchId) is taking long time to execute. So I am using Parallel.ForEach to execute it parallel. When I am using norm
Further adding to Bayu Alvian answer. I had a similar problem and I solved it by passing the context as parameter but inside the method I got
Member 'method name' cannot be accessed with an instance reference
I solved it by doing a little tweak from the above answer.
// Get the new context
HttpContext context = HttpContext.Current;
Parallel.ForEach(items, item =>
{
DoSomething(context);
}
);
private static void DoSomething(HttpContext context) {
HttpContext.Current = context;
}
Assigning the context to the HttpContext.Current removes it.