Is Task.Result the same as .GetAwaiter.GetResult()?

Jay Bazuzi picture Jay Bazuzi · Jun 24, 2013 · Viewed 132k times · Source

I was recently reading some code that uses a lot of async methods, but then sometimes needs to execute them synchronously. The code does:

Foo foo = GetFooAsync(...).GetAwaiter().GetResult();

Is this the same as

Foo foo = GetFooAsync(...).Result;

Answer

It'sNotALie. picture It'sNotALie. · Jun 24, 2013

Pretty much. One small difference though: if the Task fails, GetResult() will just throw the exception caused directly, while Task.Result will throw an AggregateException. However, what's the point of using either of those when it's async? The 100x better option is to use await.

Also, you're not meant to use GetResult(). It's meant to be for compiler use only, not for you. But if you don't want the annoying AggregateException, use it.