How to manage Thread Local Storage (TLS) when using TPL?

前端 未结 3 755
别那么骄傲
别那么骄傲 2021-02-14 10:48

I want to store logging context information in TLS so that I can set a value at the entry point, and have that value available in all resulting stacks. This work well, but I als

3条回答
  •  别那么骄傲
    2021-02-14 11:09

    I found another solution to the problem that doesn't require code. I was able to use CallContext to attach data to a "logical thread". This data is transferred from the starting thread to threads generated by TPL as well as the ThreadPool.

    http://www.wintellect.com/CS/blogs/jeffreyr/archive/2010/09/27/logical-call-context-flowing-data-across-threads-appdomains-and-processes.aspx

提交回复
热议问题