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;
            }


            
        }
    }
  • 相关阅读:
    VS2005 GridView操作大全(转载)
    架构与模式
    JS全选与取消
    C#查找指定文件夹下指定后缀名的所有文件
    select poll epoll Hello
    scanf() gets() fgets()使用注意事项 Hello
    gtk_init() Hello
    用C实现FFT算法 Hello
    时间相关函数 Hello
    gcc的编译属性和选项 Hello
  • 原文地址:https://www.cnblogs.com/dxmfans/p/9434778.html
Copyright © 2011-2022 走看看