In TPL, how do I override the execution context?

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.

Answers


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))

Need Your Help

Is it better to use mysql or files to store data?

php mysql file store

I'm wondering if it's better to use mysql or use files to store data? What is safer, what is faster? I'm talking about php and mysql.