ConfigureAwait() in .Net Core

We use ConfigureAwait(false) while calling any async method in C# to avoid blocking the current thread.

var posts = await _dbContext.Posts.ConfigureAwait(false);

The above method reads the posts asynchronously without blocking the calling thread. In .Net Framework, we need to mention ConfigureAwait(false) explicitly because by default ConfigureAwait() value is true. Microsoft made improvements with .Net Core where we are not required to mention ConfigureAwait(false) while calling the async method because by default ConfigureAwait() value is false.

var posts = await _dbContext.Posts;

The above code works well in .Net core and it reads posts without blocking the main thread.

tags:

share: