4

I am working on ASP.NET Web API 2 Application. In the application we are using for every async request:

ConfigureAwait(false);

I cannot really understand what does it mean. I looked on the internet but still don't understand what it exactly does?

3

1 Answer 1

4

To understand it, you need to understand what is Synchronization Context and Threading Models.

From practical perspective lets take a look at canonical example. You are developing GUI application (Win Forms or WPF). You have dedicated UI thread. You must update UI on UI thread and do not block UI thread by calculations or waiting some response.

ConfigureAwait have sense with async/await. By default, code after await will run on captured UI thread,

await DoAsync();
//UI updating code goes here. Will run on UI thread

Code after await will run on thread pool, if you specify ConfigureAwait(false)

await DoAsync().ConfigureAwait(false);
//CPU intensive operation. Will run on thread pool

You do not have dedicated UI thread, as far as you have ASP.NET application. But Synchronization Context is important too. Understanding the SynchronizationContext in ASP.NET will give you details.

Sign up to request clarification or add additional context in comments.

2 Comments

okay thank you. clear. but is it really important in ASP.NET Web Api 2 application?
ASP.NET threading model is more complex. But basically, there is no strict rule to use ConfigureAwait(false). The default behavior is what most likely are you expecting. It can be used for performance tuning. However, ConfigureAwait(false) considered be a good practice in library code (supposing it can be used outside ASP.NET)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.