zoukankan      html  css  js  c++  java
  • C# 异步委托回调函数使用

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;


    namespace AsyncDelegateExam
    {
        delegate int TakeAWhileDelegate(int data,int ms);


        class Program
        {
            static void Main(string[] args)
            {
                TakeAWhileDelegate del = TakeAWhile;
                del.BeginInvoke(1, 1000,
                    ar =>  //委托执行完后执行回调函数
                    {
                        int result = del.EndInvoke(ar);
                        Console.WriteLine("result:{0}", result);
                    }
    , null);


                for (int i = 0; i < 100; i++)
                {
                    Console.WriteLine(".");
                    Thread.Sleep(50);
                }
               
                Console.Read();
            }


            static int TakeAWhile(int data,int ms)
            {
                Console.WriteLine("TakeAWhile Started!");
                Thread.Sleep(ms);
                Console.WriteLine("TakeAWhile Completed!");
                return ++data;
            }


            
        }
    }
  • 相关阅读:
    关于汉密尔顿回路
    hdu 3018 Ant Trip
    hdu 1116 Play on Words
    关于欧拉回路、欧拉通路的一些定理及推论
    hdu 1531 King
    hdu 3440 House Man
    hdu 3666 THE MATRIX PROBLEM
    hdu 1384 Intervals
    关于差分约束系统
    hdu 1878 欧拉回路
  • 原文地址:https://www.cnblogs.com/dxmfans/p/9434778.html
Copyright © 2011-2022 走看看