views:

103

answers:

2

I know that when you run some method in parallel by calling BeginInvoke() or ThreadPool.QueueUserWorkItem(...) .NET framework is capturing ExecutionContext object that contains Code Access Security information and some other things.

What I want, is to include in ExecutionContext some data that is needed by my parallel method, but must be also captured at the moment of queuing the task.

Problem is that not always I do have control on the code that is creating this parallel task, so I must find a way to store this data before I call this external code. Thats why I thought about ExecutionContext class.

Is there any way to pass some state the parallel task when I'm not always in the control of the code that is splitting the work between threads.

A: 

I don't know how it relates to ExecutionContext, but back in the day, we could create context-bound objects. See Context class. Ignore the fact that this particular class is for infrastructure - the article is a starting point to learn about contexts.

John Saunders
+1  A: 

Found it:

CallContext.LogicalSetData(...)

and

CallContext.LogicalGetData(...)
SeeR