0

I am creating a cron job using .Net Core which will fetch data from API and insert data into database. Should I use ConfigureAwait(false) while calling api in asynchronous mode?

I am confused after reading article - ConfigureAwait(false) relevant in ASP.NET Core?

Since I am having console app not a UI app so Please suggest Should be go with ConfigureAwait(false) or not

Amit Agrawal
  • 51
  • 2
  • 16
  • 1
    ASP.NET Core does not have an `AspNetSynchronizationContext` (or any `SynchronizationContext`). As there is no context anymore, `ConfigureAwait(false)` is no longer needed. – trashr0x Jun 26 '20 at 10:57
  • But I read, ConfigureAwait (false) increase performance.I m having .Net core console app which is calling Api asynchronously – Amit Agrawal Jun 26 '20 at 14:39
  • if your API is not synchronized one, you can use ConfigureAwait(false) it will not stop other Tasks being run. – learner Jun 26 '20 at 14:49
  • Api has asynchronous methods so Do I need to use ConfigureAwait(false) or not with Api calls ? – Amit Agrawal Jun 26 '20 at 15:08
  • 1
    yes, you can use that. – learner Jun 26 '20 at 16:27

1 Answers1

2

In short: if you are asking, then you don't need to use ConfigureAwait(false) in your application.

.NET Core framework has no SynchronizationContext. So in this contextless approach from .NET Core, the default asynchronous behavior is the same as we have, when using ConfigureAwait(false), so when an async handler resumes execution, a thread is taken from the thread pool and goes the work.

Source: https://itnext.io/a-deep-dive-into-configureawait-65f52b9605c2