await task
instead of task.Result
await task
over task.Result
.await
does not wrap the exception in an AggregateException
, whereas Task.Result
does. Ideally, we should never have to deal with an AggregateException
at all.Task.Result
blocks until the task has completed. await
never blocks.Task.Result
can cause deadlocks in certain situations.Task.GetAwaiter().GetResult()
. This does not wrap the exception, but still suffers from blocking behavior and potential for deadlocks, so should not be used.var task = DownloadFileAsync("...");
var result = task.Result;
var task = DownloadFileAsync("...");
var result = await task;