zoukankan      html  css  js  c++  java
  • JS Async Callback

    AsyncCallback

    意义:

    异步操作完成时调用的方法

    语法1:

    构造异步回调对象

    AsyncCallback 异步回调对象名asyncCallback = new AsyncCallback(异步操作完成时调用的方法MyAsyncCallback);

    语法2:

    定义委托,并进行异步调用,异步调用完成后自动触发

    委托类型Action fn委托名 = Run委托定义;
    委托名fn.BeginInvoke(异步回调对象名asyncCallback );

    示例:

    复制代码
    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
  • 相关阅读:
    [atARC100F]Colorful Sequences
    [atARC103D]Robot Arms
    [atARC107F]Sum of Abs
    [atAGC047F]Rooks
    [loj3278]收获
    [cf809E]Surprise me
    [cf997E]Good Subsegments
    [cf603E]Pastoral Oddities
    Codeforces Round #453
    Educational Codeforces Round 32
  • 原文地址:https://www.cnblogs.com/weinixiong/p/10054536.html
Copyright © 2011-2022 走看看