国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

C#Async與Await用法

2019-11-14 13:46:21
字體:
供稿:網(wǎng)友

 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading; 6 using System.Threading.Tasks; 7  8 namespace CloudLearning.UI 9 {10     class PRogram11     {12         static void Main(string[] args)13         {14             AsyncPrintHelloWorld();15             Console.ReadLine();16         }17 18         public async static void AsyncPrintHelloWorld()19         {20             Console.WriteLine("異步方法調(diào)用開始");  21             var result1 = TMothd1();22             var result2 = TMothd2();23             var result3 = TMothd3();24             Console.WriteLine("異步方法完成");25             int r1 = await result1;26             int r2= await result2;27             int r3 = await result3;28             Console.WriteLine("{0},{1},{2}", r1, r2, r3);29         }30 31         public async static Task<int> TMothd1()32         {33             return await Task.Factory.StartNew(() =>34             {35                 Thread.Sleep(5 * 1000);36                 Console.WriteLine("TMothd1 完成");37                 return 1;38             });39         }40 41         public async static Task<int> TMothd2()42         {43             return await Task.Factory.StartNew(() =>44             {45                 Thread.Sleep(10 * 1000);46                 Console.WriteLine("TMothd2 完成");47                 return 2;48             });49         }50         public async static Task<int> TMothd3()51         {52             return await Task.Factory.StartNew(() =>53             {54                 Thread.Sleep(15 * 1000);55                 Console.WriteLine("TMothd3 完成");56                 return 3;57             });58         }59 60     }61 }
View Code

 


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 株洲市| 旬阳县| 色达县| 泗洪县| 墨竹工卡县| 琼结县| 桐柏县| 仙居县| 肇州县| 呼伦贝尔市| 出国| 昌宁县| 定州市| 蕲春县| 库尔勒市| 沭阳县| 喀什市| 区。| 昌黎县| 乌鲁木齐县| 当雄县| 遂宁市| 昌宁县| 开鲁县| 池州市| 额敏县| 淮南市| 贵溪市| 内江市| 开平市| 巴马| 乌苏市| 宝兴县| 英山县| 宿州市| 仪征市| 武威市| 万盛区| 宜宾市| 灯塔市| 乌恰县|