A summary of new asynchronous programming features in 4.5
1. Async marked with async should use the await key to make a hang start. The await operator tells the compiler that the Async method cannot continue until it is finished, and that the control is transferred to the caller of the Async method
2. An async method typically contains one or more corresponding await operators, but does not cause compilation errors if no await expressions are present. But if you call an async method without using the AWAIT keyword to mark a hanging start, the program ignores the ASYNC keyword and executes it synchronously
3. If you specify task<tresult> as the return result, then this method must contain a statement that returns the TResult result specified by the return.
If a task is used as the return value, then the method should not have code that returns the result using the return statement, or the returned result does not participate in any operations (including assignment operations)
The 4.async and await keywords do not create additional threads, and the Async method does not request multithreaded operations. The operation that actually creates the thread is implemented by the Task.run ()
5. Inside an async method, when an asynchronous request (Httpclient.sendasync) is invoked, the other tasks of the main thread are processed, and the awaite waits for the completion of the asynchronous operation where the asynchronous operation is required to return the result Httpclient.sendasync tasks and tasks in the main thread are run in parallel (so you can take full advantage of the CPU's resources) there are two situations where a. An asynchronous task that SendAsync when calling Awaite has completed this time await Responsemsgtask is in the main thread, B at Awaite when the asynchronous task of SendAsync is not completed this time the main thread of the task will be blocked until the asynchronous task is completed and reactivate the main thread subsequent task this time await The Responsemsgtask is in the asynchronous thread
The code after 6.Await can also be placed in the task ContinueWith segment to run
Grammar sugar!!!
Transferred from: http://www.cnblogs.com/chengruhui/archive/2013/02/28/2937356.html
Async & Await