Await vs Task.Result in an Async Method

luis picture luis · Aug 27, 2015 · Viewed 88.7k times · Source

What's the difference between doing the following:

async Task<T> method(){
    var r = await dynamodb.GetItemAsync(...)
    return r.Item;
}

vs

async Task<T> method(){
    var task = dynamodb.GetItemAsync(...)
    return task.Result.Item;
}

In my case, for some reason, only the second works. The first one never seems to end.

Answer

Frank Fajardo picture Frank Fajardo · Aug 27, 2015

await asynchronously unwraps the result of your task, whereas just using Result would block until the task had completed.

See this explanantion from Jon Skeet.