[flash=500,400]http://s1.knowsky.com/20160211/fsnj4ptdtgr56.jpg[/flash]
[flash=500,400]http://s1.knowsky.com/20160211/2w2i23bb1y256.gif[/flash][flash=500,400]http://s1.knowsky.com/20160211/i1ioyayvgqc56.gif[/flash]1usingSystem;2usingSystem.Collections.Generic;3usingSystem.Linq;4usingSystem.Text;5usingSystem.Threading;6usingSystem.Threading.Tasks;78namespaceCloudLearning.UI9{10classPRogram11{12staticvoidMain(string[] args)13{14AsyncPrintHelloWorld();15Console.ReadLine();16}1718publicasyncstaticvoidAsyncPrintHelloWorld()19{20Console.WriteLine("异步方法调用开始");21varresult1 =TMothd1();22varresult2 =TMothd2();23varresult3 =TMothd3();24Console.WriteLine("异步方法完成");25intr1 =awaitresult1;26intr2=awaitresult2;27intr3 =awaitresult3;28Console.WriteLine("{0},{1},{2}", r1, r2, r3);29}3031publicasyncstaticTask<int>TMothd1()32{33returnawaitTask.Factory.StartNew(() =>34{35Thread.Sleep(5*1000);36Console.WriteLine("TMothd1 完成");37return1;38});39}4041publicasyncstaticTask<int>TMothd2()42{43returnawaitTask.Factory.StartNew(() =>44{45Thread.Sleep(10*1000);46Console.WriteLine("TMothd2 完成");47return2;48});49}50publicasyncstaticTask<int>TMothd3()51{52returnawaitTask.Factory.StartNew(() =>53{54Thread.Sleep(15*1000);55Console.WriteLine("TMothd3 完成");56return3;57});58}5960}61}
View Code