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. Google Maps API v2 Demo Tutorial

    申请API KEY https://code.google.com/apis/console/?noredirect 1. 创建项目,名称随意,只是为了区分 2. 开启Google Maps Andr ...

  2. Codeforces 628E Zbazi in Zeydabad 树状数组

    题意:一个n*m的矩阵,要么是 . 要么是 z ,问可以形成几个大z 分析:(直接奉上官方题解,我感觉说的实在是太好了) Let's precalculate the values zlij, zri ...

  3. 用户名 不在 sudoers文件中,此事将被报告。

    原文解决方法:http://blog.csdn.net/lincyang/article/details/21020295 CentOS7.0 用到sudo权限的时候出现的问题,如题. sudo命令可 ...

  4. Debug Assertion Failed!

    问题并没有解决..... 不知道怎么回事,先都没有这样的情况... VC++调程序出现如下错误: Debug   Assertion   Failed!       Program:   D:wyuS ...

  5. 1.2CPU和GPU的设计区别

    CPU和GPU之所以大不相同,是由于其设计目标的不同,它们分别针对了两种不同的应用场景.CPU需要很强的通用性来处理各种不同的数据类型,同时又要逻辑判断又会引入大量的分支跳转和中断的处理.这些都使得C ...

  6. iptables端口重定向

    需求:     tomcat容器使用普通用户启动不能开启1024以内端口,也就80端口不能使用.业务上通常使用80端口访问. 解决方法:     iptables既是防火墙也是带路由器功能.所以使用它 ...

  7. Unity3D为FirstPersonController添加跑步与下蹲动作

    using UnityEngine; using System.Collections; public class MyController : MonoBehaviour { ; ; ; priva ...

  8. 让浏览器进行跨域访问, 开发阶段需要跨域访问的测试方案 chrome的快捷方式里面 加 "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --args --disable-web-security

    Chrome浏览器 的快捷方式里加一个 命令可以使浏览器进行跨域访问 "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe ...

  9. socket.io使用随笔

    这段时间一直在做一个手机APP,正好使用到了socket.io.这里记录一下服务器端发送信息的几种不同方式: socket.emit('message',"this is a test&qu ...

  10. hdoj 2050 折线分割平面

    折线分割平面 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...