I explain this deadlock situation on my blog and in an MSDN article.
The short summary is that await
(by default) will capture the current context and resume the async
method within that context.
In UI apps, that context is a UI context, but if you are blocking the thread with a call to Wait
, then the async
method can't re-enter the UI context to complete.
In (most) unit testing frameworks, the context is a thread pool context, so the Wait
only blocks one thread pool thread and the async
method can continue on another one.