Is there a way to read the value of an AsyncLocal value as another thread would see it?
Assume I have a thread executing and there I set a value. Now from another thread, with means like reflection or Microsoft.Diagnostics.Runtime, I would like to read the value of this AsyncLocal
and get the value that would be returned if I would access it from the first thread. I want to observe what value is there in another async flow from the outside.
I know how AsyncLocal
works and that it is not a value "fixed" to a thread. But I would like to know the value that a particular thread would get when reading the AsyncLocal
.
Important
In the past I had a value in the LogicalCallContext
on the ExecutionContext
of a thread and was able to read it through reflection. So now I look for an alternative that works with AsyncLocal
. The actual application of this was a diagnostics functionality.
Update
Looking at the code of AsyncLocale
here made me thing there might be a way to retrieve this informaiton somehow. But when I tried I only saw that I would be able to read some AsyncLocales but not the one I was actually looking for. So I would be eager to know where this information is living in the CLR. Where is the data of the AsyncLocale
living in the CLR?