Let's say I have this code
ThreadPool.QueueUserWorkItem(unused =>
{
SynchronizationContext.SetSynchronizationContext(
new MyCustomSynchronizationContext());
// not reset back to null
}, null);
The current synchronization context is leaked back to thread pool. If someone calls ThreadPool.QueueUserWorkItem again and the same thread is used to process the other work item, will the current synchronization context of that thread be reset back to null or will it stay MyCustomSynchronizationContext?
Does the same answer apply to any other way for executing tasks on the thread pool e.g. Task.Run, BeginInvoke, etc.?
I know that in general the TLS is not reset but .NET source code shows that the storage of the current synchronization context is not very clearly defined (most of the time it comes from the executioncontext but it seems to be special cased for WinRT for some reason).