C# 5.0: async/await declarations
In order to enhance the possibilities of creation and the management of asynchronous processes and to simplify the code even more, version 5.0 of C# introduced a couple of new reserved words in order to facilitate the insertion of asynchronous calls without having to implement an extra method to receive the results: the couple of words are async
/await
(one cannot be used without the other).
When a method is marked as async
, the compiler will check for the presence of another sentence prefixed with the await
keyword. Although we write the method as a whole, the compiler fragments (internally) the method into two parts: the one where the async
keyword appears initially, and the rest counting from the line in which await
is used.
At execution time, as soon as the await
sentence is found, the execution flow returns to the calling method and executes the sentences that follow, if any. As soon as the slow process returns, execution continues with the rest of sentences...