0

When using async/await in TPL, will it reuse idle threads and in theory invoke callbacks on other threads than used initially?

About AsyncLocal in this context, will it pass its value around to match the flow or could I end up with a value from another reused thread?

Andreas Zita
  • 7,232
  • 6
  • 54
  • 115

1 Answers1

2

Async-await will pick a random thread from the thread-pool, unless there is a SynchronizationContext, which can force TPL to continue on the same thread.

The idea of AsyncLocal is to persist a value across threads. It is ThreadLocal that is thread-specific.

Nick
  • 4,787
  • 2
  • 18
  • 24