在C#中使用异步 async await
1 class Program 2 { 3 public static async Task Main(string[] args) 4 { 5 var result = await Save(); 6 Console.WriteLine(result); 7 Console.ReadLine(); 8 9 } 10 11 public static async Task<string> Save() 12 { 13 var wc = new WebClient(); 14 var result = await wc.DownloadStringTaskAsync("https://www.baidu.com/"); 15 await Task.Run(() => 16 { 17 File.WriteAllText("D:/reuslt.txt", result); 18 }); 19 return "Success write"; 20 21 } 22 23 }