What await means
The await
keyword is used to make asynchronous calls, so if the method being called is delayed, everything that comes after the call using await
is suspended, waiting to be executed in a queue.
For example:
código parte 1;
await FazerAlgoQuePodeDemorar();
código parte 2;
If the function called FazerAlgoQuePodeDemorar
in your internal implementation is delayed, it will stop, leaving código-parte-2
on hold, waiting to be executed after the completion of the internal processing of the called function using await
.
And in the context of MVC?
An MVC action that is defined with async
, allows a method within it to be called with await
, causing the MVC not to occupy the queue of requests that are processed by the server, until the called method with await
complete, and finally return a result.
This was done because each time a non-synchronous action is called, it occupies a thread that is available to handle requests, and there is a limit to the number of threads that do this job. Using async
, the request processing thread is released to process other requests, whereas a call made with await
handles the processing of the request previously made in another plan.
This is only really useful, for actions that make I / O calls, such as access to databases, requests to external servers, hard disk recordings, among other tasks that can be done asynchronously.
References
MSDN: Using an asynchronous controller in ASP.NET MVC
In this MSDN topic, it has a very explanatory picture of what happens, basically everything that comes after the call using await
in the asynchronous action, is transferred to another thread, other than the pool that answers requests, therefore, free to attend other requests.
This blog , in English , explains exactly the asynchronous actions calls, using async
and why their use causes the server to be able to serve more requests simultaneously.