using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading; //异步调用
//returntype EndInvoke(ref_out_argument,AsyncWaitHandle ar) namespace Starter
{
public delegate int DeleageteClass(out DateTime start, out DateTime stop); class Program
{
static void Main(string[] args)
{
DeleageteClass del = MethodA;
DateTime start;
DateTime stop; IAsyncResult ar = del.BeginInvoke(out start, out stop, null, null); ar.AsyncWaitHandle.WaitOne(); //do something else //EndInvoke返回一个一步结果
int elapse = del.EndInvoke(out start, out stop, ar); Console.WriteLine("start: "+ start.ToLongTimeString());
Console.WriteLine("stop: " + stop.ToLongTimeString());
Console.WriteLine("elapse: " + elapse); Console.ReadLine();
} public static int MethodA(out DateTime start,out DateTime stop)
{
start = DateTime.Now;
Thread.Sleep(5000);
stop = DateTime.Now;
return (stop-start).Seconds;
}
} }

C#_delegate EndInvoke的更多相关文章

  1. C#_delegate - 异步调用实例 BeginInvoke EndInvoke event

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  2. 多线程 异步 beginInvoke EndInvoke 使用

    有许多耗时操作时,还要响应用户操作.这时候就需要用其他线程或者异步来搞.本来是改造公司的日志组件.因为多上了个国外大区的业务到来本系统来.这个系统其他地方都好就是日志,动不动就要死给我们看.有时候寻找 ...

  3. .NET C#-- 利用BeginInvoke与EndInvoke完成异步委托方法并获取方法执行返回值示例

    //定义委托 delegate string MyDelegate(string name); //定义委托调用函数 public string Hello(string name) { Thread ...

  4. .net3.5后新增的 BeginInvoke EndInvoke 异步操作

    protected void Main() { //首先定义一个方法的封装..后边的LongTimeMethod是被封装的方法.. Func<int> longTimeAction = n ...

  5. BeginInvoke与EndInvoke方法解决多线程接收委托返回值问题

    BeginInvoke与EndInvoke方法解决多线程接收委托返回值问题 原文:http://www.sufeinet.com/thread-3707-1-1.html      大家可以先看看我上 ...

  6. C#线程系列讲座(1):BeginInvoke和EndInvoke方法

    一.C#线程概述 在操作系统中一个进程至少要包含一个线程,然后,在某些时候需要在同一个进程中同时执行多项任务,或是为了提供程序的性能,将要执行的任务分解成多个子任务执行.这就需要在同一个进程中开启多个 ...

  7. [转]BeginInvoke和EndInvoke方法浅析

    开发语言:C#3.0   IDE:Visual Studio 2008   一.C#线程概述   在操作系统中一个进程至少要包含一个线程,然后,在某些时候需要在同一个进程中同时执行多项任务,或是为了提 ...

  8. C# 对委托的BeginInvoke,EndInvoke 及Control 的BeginInvoke,EndInvoke 的理解

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  9. delegate 中的BeginInvoke和EndInvoke方法

    开发语言:C#3.0 IDE:Visual Studio 2008 一.C#线程概述 在操作系统中一个进程至少要包含一个线程,然后,在某些时候需要在同一个进程中同时执行多项任务,或是为了提供程序的性能 ...

随机推荐

  1. error MSB3027: Could not copy "xxx.dll" to "xxx.dll". Exceeded retry count of 10. Failed.

    错误提示内容: C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(3363,5): error MSB302 ...

  2. [LeetCode] Two Sum水过

    刷LeetCode的第一题,TwoSum,基本算是水过. 题目:https://leetcode.com/problems/two-sum/ Given an array of integers, f ...

  3. javascript——继承

    内容: 1.继承的概念.继承分为那几种继承及各种继承的区别 2.js中有那几种继承方式及各种继承的优缺点 3.总结

  4. weiphp3.0(thinkphp)的调整之路

    weiphp是在thinkphp的基础上开发的简洁强大开源的微信公众平台开发框架,其宣称微信功能插件化开发,多公众号管理,配置简单. 但是关于weiphp的文档使用一是内容真不多,二是写的也不详细. ...

  5. Visual Studio 2015 编译错误【错误 C4996 'vsprintf': This function or variable may be unsafe. Consider using vsprintf_s instead. 】的解决方案

    错误提示信息: 错误 C4996 'vsprintf': This function or variable may be unsafe. Consider using vsprintf_s inst ...

  6. acm数据结构整理

    一.区间划分 //区间划分+持久化并查集:区间连通情况统计. inline bool comp(Ask x, Ask y){return x.km == y.km ? x.l > y.l : x ...

  7. CSU 1515 Sequence (莫队算法)

    题意:给n个数,m个询问.每个询问是一个区间,求区间内差的绝对值为1的数对数. 题解:先离散化,然后莫队算法.莫队是离线算法,先按按询问左端点排序,在按右端点排序. ps:第一次写莫队,表示挺简单的, ...

  8. android界面优化笔记(TODO)

    1.避免使用线性布局的层层嵌套,要使用相对而已.使用线性布局越多,嵌套越多 官方文档: Optimizing Your UI

  9. Windbg分析DMP文件

    1.提取Dump格式文件 有两种方式: 第一种,程序崩溃时,启动任务管理器,选择崩溃的*.exe进程,右键选择创建转储文件,通过 开始—运行—输入 %temp% --确定--在打开Temp窗口中即可找 ...

  10. JavaScript的this简单实用

    1.默认绑定全局变量,在全局函数中: function fn(){ console.log(this.a); } var a=2; fn();//这里调用的是window 2.隐式绑定: functi ...