What is the difference between await and ConfigureAwait(false).GetAwaiter().GetResult();

1.6k Views Asked by At

Let's say I got an async method in C# .Net Core:

public Task<ResultClass> Action() { ... }

What is the difference between invoking: ResultClass res = await Action();

and invoking: ResultClass res = Action().ConfigureAwait(false).GetAwaiter().GetResult();

1

There are 1 best solutions below

10
On

The await keyword will free the current thread during the work. So if you have a limited number of thread it's really useful.

The "GetAwaiter().GetResult()" will do the same but synchronously so the current thread will be blocked during the work.

The "ConfigureAwait(false)" is a configuration that have no sense if you are in synchronous code but can be usefull with the await

await Action().ConfigureAwait(false);

That you ensure the following will be called directly and avoid potential dead locks.