As we all know (except for the unknown), C#5 has added an asynchronous wait function to be able to easily implement asynchronous waiting. The rule is this:
Precede the asynchronous method with the await keyword, and the method that calls the asynchronous method must precede a async keyword.
Like this:
Async void Dodelayasync ()
{
await task.delay (999999999);
}
The code executes synchronously while entering the Dodelayasync method, until the await operator is encountered, and the application does not die until the task is finished, which is pretty good in the user interface, when the code is waiting for the asynchronous operation to complete in await. Users can still manipulate other elements on the interface.
In the past, to do this, it is often necessary to recall from another thread, using a delegate to callback. Now using the await operator is simpler than n times.
I received a spam message last night, it was really junk mail, because I saw a unread letter in the trash bin. Do not know who, anyway, even the name is not afraid to report up. He raised such a question.
Async static void Main (string[] args)
{
await task.delay (8000);
Console.read ();
}
This man is very powerful, unexpectedly at the entry point also played the asynchronous wait, I guess he was the inner world must be colorful, open experience can not describe, because he is about to discover Newland, at the entry point can also asynchronous await. Then I thought that his inner world must have become China. I reckon that when he pressed the F5, he found the following fright.
Obviously, the compiler does not want him to find the new world, ruthlessly give him a heavy blow.
Yes, in the method inside with await asynchronous wait, that call method must be in front plus async, but this method is main, you take him no way. What can we do about it?