Why does AsyncLocal<T> propagate to child threads whereas ThreadLocal<T> does not? Why does AsyncLocal<T> propagate to child threads whereas ThreadLocal<T> does not? multithreading multithreading

Why does AsyncLocal<T> propagate to child threads whereas ThreadLocal<T> does not?


AsyncLocal stores the data in the execution context, which is automatically flown by most APIs (including Task.Run).

One way to prevent that is to explicitly suppress flow whenever needed:

using (ExecutionContext.SuppressFlow()){    Task.Run(...);}