JS Async Callback

AsyncCallbackhtml

意義:異步

異步操做完成時調用的方法async

語法1:spa

構造異步回調對象code

AsyncCallback 異步回調對象名asyncCallback = new AsyncCallback(異步操做完成時調用的方法MyAsyncCallback);htm

 

語法2:對象

定義委託,並進行異步調用,異步調用完成後自動觸發blog

委託類型Action fn委託名 = Run委託定義;
委託名fn.BeginInvoke(異步回調對象名asyncCallback );ci

 

示例:string

複製代碼
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 /// 異步調用來自:https://www.cnblogs.com/licin/p/8274405.html
相關文章
相關標籤/搜索