Home c# Await + Configureawait ()

Await + Configureawait ()




Colleagues, good afternoon. I ask for help with configureawait ().

My knowledge at this level : This is a method that indicates the implementation environment that when returning from an asynchronous method (running in another stream), you do not need to use the synchronization context. Those. Do not wait until the flow is free, in which the code execution has begun (before AWAIT), and continue the execution of the code (which after Await) in the same stream, in which asynchronous task itself (await itself) was performed.
It improves performance, but it is worth using with caution in tasks where UI streams are present (WPF, ASP.NET). correct please if I’m wrong.

and then the second question arises. Suppose I have such a chain of asynchronous calls:

Public Async Task M1 ()
  Public Async Task M2 ()
  Public Async Task M3 ()
    Return await.
          .Tolistasync ()
          .Configureawait (false);

In the M3 () method, an asynchronous wait occurs. EF creates a new stream and reads from the database, we are waiting. All ok.

And what happens in m2 ()? Whether a new stream is created to perform AWAIT M3 () . A similar question for the M1 () method. Is it worth using configureawait (false) in these await-ah, or it is enough that we used this method in M3 ()?

Answer 1, Authority 100%


Configureawait (false) acts directly only on AWAIT , which expects this Task (more precisely, this Tasklike ). This means that in the external function will be captured by the context in the usual way, and the execution will return there at the end of AWAIT . What or in which contexts the code M1 does not play the role if m2 runs in a synchronization context.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions