Q: ControllerContext throwing error in Parallel.ForEach in mvc c# I have function which return string and it has parameter of ControllerContext and this is throwing error
Here is code
        var cContext = ControllerContext;

       Parallel.ForEach(listInvHeaderIDs, x =>         
       {

        body = new myClass().myFunctionReturnString(cContext);

       }

Can we use ControllerContext in Parallel.Foreach if not than what to use

A: You can probably try this overload of the Parallel.ForEach:
public static ParallelLoopResult ForEach<TSource, TLocal>(IEnumerable<TSource> source, 
      Func<TLocal> localInit, Func<TSource, ParallelLoopState, TLocal, TLocal> body,
      Action<TLocal> localFinally)


Executes a foreach operation with thread-local data on an IEnumerable in which iterations may run in parallel, and the state of the loop can be monitored and manipulated.

An example of usage:
UDPATE
I've updated the example, should be ok now.
Parallel.ForEach(listInvHeaderIDs, () => {return cContext; }, 
(listId, loopInfo, ctrlContext) =>            
{
    body = new myClass().myFunctionReturnString(ctrlContext);
    return ctrlContext;
}, 
(ctrlContext) => { /*access controller context if needed...*/} );

