When to Use ConfigureAwait() in Asp.net Core 3.1 Code
Question: What is ConfigureAwait(true) in Asp.Net Core 3.1 C#, I have noticed the compiler recommending me to use ConfigureAwait(true) or ConfigureAwait(false).
Login to See the Rest of the Answer
Answer: According to Microsoft's Developer Blog using ConfigureAwait(false) is recommended as the C-Sharp Compiler finds an awaiter (a line of code with an await directive specified) and continues executing the code on the Original Thread while awaits for a response from another function.
When the response completed, the async function won't notify the awaiter on the Main Thread but will provide the response data on a different thread, leaving the Original/Main Thread undisturbed.
For example, if the response expected from the function call is not awaited by another function somewhere in the application code, use ConfigureWait(true) or rather use _ = functionName(Parameter).ConfigureAwait(true);
Mark said:
You have to be very careful using ConfigureAwait(false), otherwise do not call an async function from a none Async Function, this will produce a very weird behavior that will be very had to diagnose. I would encourage you to read more about Threading, it is a very complex topic.