Once, we may have used thread. When the main thread is running. A new thread is opened to run the new method.
Today to see someone sent me a piece of code to find a not know the await, but also feel very familiar with the look, feel is the thread that the thing, check the next, found a simple way to realize multi-threaded asynchronous programming.
(Ps:framework at 4.5 or more talent enough oh ~)
<summary> //test method ///</summary>//<remarks> Creator: Liu Huishuo; time: 2015-08-24 20:22:14 </remarks> public async static void Asyncprinthelloworld () { Console.WriteLine ("Asynchronous Method call Start"); Console.WriteLine ("Async Method: Hello World"); . NET Framework 4.5 and above version number await Task.delay (1000);//Open a new thread here to process, and make a test.。 Console.WriteLine ("Exit Async Method"); }
Main call:
Console.WriteLine ("=============== Async method call ==========="); Asyncprinthelloworld (); Console.WriteLine ("************* is now running the main thread method **************"); Console.readkey ();
Method results:
Add Keywordasync to the method, at the same time, for the method where the new thread is to be opened. Add Awaitkeyword, then this will open another thread to handle, the main thread continues, the method here to run the results.
Very good fun, do not know which day to use.
。
。。。
C#--await and Async for multithreaded asynchronous programming