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;
            IAsyncResult ar = del.BeginInvoke(1, 1000, null, null);
            while (true)
            {
                Console.WriteLine(".");
                if (ar.AsyncWaitHandle.WaitOne(50,false))
                {
                    Console.WriteLine("Can Get Result now!");
                    break;
                }
            }
            int result = del.EndInvoke(ar);
            Console.WriteLine("result:{0}", result);
            Console.Read();
        }

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

        
    }
}

最新文章

  1. shell-脚本入门【转】
  2. 【工具】CodeSmith Generator 7.0.2激活步骤
  3. Android中关于Volley的使用(五)从RequestQueue开始来深入认识Volley
  4. try : finally语句
  5. chrome拓展开发实战
  6. jQuery 遍历用法
  7. testlink于smarty配置和使用
  8. 解决python中flask_sqlalchemy包安装失败的问题
  9. ASP.NET Core WebApi使用Swagger生成api说明文档看这篇就够了
  10. Maven替换为国内仓库
  11. error LNK1169 找到一个或多个多重定义的符号的解决方法
  12. Attempted to serialize java.lang.Class: org.hibernate.proxy.HibernateProxy. Forgot to register a type adapter?
  13. 如何安装MySQL5.5.62
  14. Glibc堆块的向前向后合并与unlink原理机制探究
  15. Apache多站点配置(ubuntu)(原创)
  16. Centos下PPTP环境部署记录
  17. PTA 7-6 列出连通集(深搜+广搜)
  18. Underscore.js 入门-常用方法介绍
  19. css 让div 置于最顶层而不被其他东西挡住
  20. [翻译] UIColor-uiGradientsAdditions

热门文章

  1. redisson
  2. jquery-5 jQuery筛选选择器
  3. [Angular] Ngrx/effects, Action trigger another action
  4. 关于ulimit -a中需要修改的两个值
  5. @RequiresPermissions 解释
  6. 【vs调试】PDB 文件:每个开发人员都必须知道的
  7. NOIP模拟 回文序列 - DP
  8. Ubuntu安装编译OpenCV一键脚本(带ffmpeg)
  9. require.js的用法详解
  10. 学习鸟哥的Linux私房菜笔记(15)——文件系统