I have a C# webserver which I have been profiling using the StackOverflow miniprofiler. Because it's not an ASP.NET server, but each request was typically executed on its own thread, I rigged the miniprofiler to use ThreadStatic
storage to track all of the profilers of an incoming request from start to finish. This worked well.
Recently we've converted everything to use async/await
, which means continuations after an await
typically don't come back onto the same Thread
and thus the ThreadStatic
storage no longer works.
What's the best way to pass some small piece of data between different ThreadPool
threads in this case? Are there existing SynchronizationContext
implementations that would be useful for something like this?