Yes, you're currently creating a deadlock.
You're using async/await, which means that when the task returned by DownloadStringTaskAsync
completes, a continuation will be scheduled to continue loadAsync
from where it left off, and back in the UI thread.
However, that continuation is never going to actually run because the UI thread is busy waiting for a task to complete... and that task is only going to complete after continuation has run. Deadlock.
Just to block the UI thread, you don't need to use async
/await
at all:
// Method name changed to follow .NET conventions.
public static string Load() {
WebClient webClient = ...;
Task<string> task = webClient.DownloadStringTaskAsync(uri);
return task.Result; // Result blocks, just like Wait().
}