The call to Task.Wait
and Task.Result
is causing the deadlock. I explain this in detail on my blog and in a recent MSDN article.
In short, when you await
a Task
that has not yet completed, by default it will capture a "context" and use that to resume the async
method. In your case, this is the UI context. However, when you call Wait
(or Result
), you're blocking the UI thread, so the async
method cannot complete.
To fix this, use await
instead of Wait
/Result
, and use ConfigureAwait(false)
everywhere you can.