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