Async when continuing on another thread
Async when continuing on another thread I know that a Task may continue the execution on another thread, proven by this code. public async Task Test() { var id1 = System.Environment.CurrentManagedThreadId; await Task.Delay(1000); var id2 = System.Environment.CurrentManagedThreadId; Console.Write($"First {id1} then {id2}"); } I expect the framework to handle memory barrieres, so that id1 is visible when accessed in the last statement. But what if you are using some kind of framework e.g. NHibernate where the ISession is not thread safe. Frameworks may even check that the thread ID is still the same. How does this mix? When building website, I'll to use a IOC container with a nested container per request, but when then thread could change within the same request, wouldn't this lead to all kind of problems? ThreadStatic would not work as expected 1 Answer 1 ...
