Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Ironically it is essentially the event loop which causes the deadlock in C#.

Depending on what framework/runtime you're in .NET will schedule the await continuation on something called a "SynchronizationContext" which has ~3 different forms but it's basically an event loop/message loop which queues up each continuation on the original thread.

The problem occurs when you use .Wait() or .Result instead of 'await'. This causes the function to spin waiting for the Task to finish, which of course it never will if it has a continuation trying to dispatch into that same event loop.

This problem doesn't really happen at all under some circumstances, such as if the async chain starts on a background thread, or in .net core where they've removed the SynchronizationContext, hence no event loop, hence no problems.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: