In TPL, how do I override the execution context?
-
14-06-2021 - |
Question
How do I override the execution context when creating a new Task object? I want to use one that I previously captured using ExecutionContext.Capture.
Solution
The same as you would when not using TPL: using ExecutionContext.Run()
. For example:
Task.Factory.StartNew(
() => ExecutionContext.Run(
ec, _ => Console.WriteLine(CallContext.LogicalGetData("foo")), null))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow