AsyncCallback異步
意義:async
異步操做完成時調用的方法spa
語法1:code
構造異步回調對象對象
AsyncCallback 異步回調對象名asyncCallback = new AsyncCallback(異步操做完成時調用的方法MyAsyncCallback);blog
語法2:string
定義委託,並進行異步調用,異步調用完成後自動觸發it
委託類型Action fn委託名 = Run委託定義;
委託名fn.BeginInvoke(異步回調對象名asyncCallback );io
示例:class
using System; namespace Examples.AdvancedProgramming.AsynchronousOperations { public class UseDelegateForAsyncCallback { delegate string MethodDelegate(int iCallTime); public static void Main() { MethodDelegate dlgt = (m)=> { return "你輸入的數字是"+m; }; AsyncCallback asyncCallback = new AsyncCallback(MyAsyncCallback); Action fn = Run; fn.BeginInvoke(asyncCallback,null); } private static void MyAsyncCallback(IAsyncResult ar) { Console.WriteLine("異步調用"); Console.ReadLine(); } public static void Run() { } } } /// 控制檯輸出結果: /// 你輸入的數字是:5 /// 異步調用