c# - Passing data between ThreadPool threads -


i have c# webserver have been profiling using stackoverflow miniprofiler. because it's not asp.net server, each request typically executed on own thread, rigged miniprofiler use threadstatic storage track of profilers of incoming request start finish. worked well.

recently we've converted use async/await, means continuations after await typically don't come onto same thread , threadstatic storage no longer works.

what's best way pass small piece of data between different threadpool threads in case? there existing synchronizationcontext implementations useful this?

what's best way pass small piece of data between different threadpool threads in case?

using logical call context via static callcontext class. exposes 2 methods: logicalsetdata , logicalgetdata. call context stored , marshaled via executioncontext, in charge of sync context, etc.

using class has 2 restrictions:

  1. you're limited use of .net 4.5 , above

  2. logical call context uses copy-on-write semantics, , performs shallow copy once data mutated. means should using immutable data, references may shared across multiple threads.

one last thing note callcontext initialized once call it. means when using it, you're taking on overhead because of copy-on-write.

more on can found in post stephan cleary called implicit async context


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -