Today the two key words to make a little dizzy, mainly still did not thoroughly understand the principle.
Confuses the concept of invoking an async method :
When you call an async method, the method returns a Task, but the code in it begins to execute. The method immediately executes a portion of the code at the time of invocation, directly at the bottom of the async API to produce a true asynchronous operation, which is then incrementally returned and eventually uses a task to represent the asynchronous task.
The Async method is also executed asynchronously when the await keyword is not used. After using the await keyword, it is simply a Task (awaitable) object that asynchronously waits for its execution to end, and then executes subsequent code in the same context.
If you use an await task. Configureawait (False), which indicates that the code after the line does not need to be executed in the same context.
In other words, for a call to Task Run ():
1. RunAsync (): Executes the Async method directly, followed by subsequent code execution.
2. Await RunAsync (): Executes the Async method and executes the subsequent code after the end (the code that precedes this line of code executes in the same thread).
3. Await RunAsync (). Configureawait (FALSE): Executes the Async method and executes subsequent code after the end (the thread being executed is not specified).
Use of Await
Also, because await is only for awaitable objects, it is not required to be used before an async method. You can use await at the appropriate time, for example:
var task = RunAsync ();//start asynchronous operation.
Dosth ();//The main thread performs other operations at the same time.
Await task;//at this time waiting for asynchronous execution to complete.
Dootherthing ();//Perform other operations.
Reference:
Below, list several articles related to async await
Dudu: Practical case: Implementing parallelism in existing code through ASYNC/AWAIT
Behind the implementation of the Async/await
Instructions for using async and await in MVC
Async & await Past life (Updated)
C # async/await Usage Summary