From what I know, AspNetCore doesn't have SynchronizationContext
.
That “re-entering” the request context involves a number of housekeeping tasks, such as setting HttpContext.Current and the current thread’s identity and culture.
So I've created a simple .Net Core Api project with an action:
[HttpGet]
[Route("checkVar")]
public async Task<IActionResult> checkVar()
{
Thread.SetData(Thread.GetNamedDataSlot("Random"),4);
await Task.Delay(1000);
var res = Thread.GetData(Thread.GetNamedDataSlot("Random"));
}
To my suruprise , res
had a value of 4
. I was surprised because I believe that SetData
was part of the synchronization context. (which should not exist in asp.net core)
More, when I used ConfigureAwait(false)
, I got null
in res
.
So now I'm confused. Because ConfigureAwait
shouldn't have effect in asp.net core
Question:
If asp.net core doesn't have a SynchronizationContext, then why did 4
was available after await
? why does the ConfigureAwait
change the result in a non-SynchronizationContext environment?