先模擬一個需要異步的函數,等待5秒
public class Math { public int Add(int i, int j) { Thread.Sleep(5000); Console.WriteLine("計算完成!"); return i + j; } }然后寫一個委托
delegate int Sum(int a,int b);Task做一個簡單的泛型
static Task<int> GetSum(int a, int b) { Math mAdd = new Math(); return Task.Run<int>(() => { return mAdd.Add(a, b); } );}然后在Main里調用
static void Main(string[] args) { HqlpSum(); Console.WriteLine("計算中。。。"); }輸出結果: 
異步才符合做事標準-。-!
歡迎關注我的微信個人訂閱號 
 我的微博:well火柴 每天多學一點0.0
新聞熱點
疑難解答