❔ ThreadStatic for tasks
I need something that acts like ThreadStatic, but for async/await code.
In my case, I need to set a context value.
For example, in ASP.NET I want to set the HttpContext to have a value I want to access later, but only from this task and its children.
How might I do this?
2 Replies
I think you're probably looking for "AsyncLocal<T>": https://learn.microsoft.com/en-us/dotnet/api/system.threading.asynclocal-1?view=net-7.0
AsyncLocal Class (System.Threading)
Represents ambient data that is local to a given asynchronous control flow, such as an asynchronous method.
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.