C#_delegate EndInvoke
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的更多相关文章
- C#_delegate - 异步调用实例 BeginInvoke EndInvoke event
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 多线程 异步 beginInvoke EndInvoke 使用
有许多耗时操作时,还要响应用户操作.这时候就需要用其他线程或者异步来搞.本来是改造公司的日志组件.因为多上了个国外大区的业务到来本系统来.这个系统其他地方都好就是日志,动不动就要死给我们看.有时候寻找 ...
- .NET C#-- 利用BeginInvoke与EndInvoke完成异步委托方法并获取方法执行返回值示例
//定义委托 delegate string MyDelegate(string name); //定义委托调用函数 public string Hello(string name) { Thread ...
- .net3.5后新增的 BeginInvoke EndInvoke 异步操作
protected void Main() { //首先定义一个方法的封装..后边的LongTimeMethod是被封装的方法.. Func<int> longTimeAction = n ...
- BeginInvoke与EndInvoke方法解决多线程接收委托返回值问题
BeginInvoke与EndInvoke方法解决多线程接收委托返回值问题 原文:http://www.sufeinet.com/thread-3707-1-1.html 大家可以先看看我上 ...
- C#线程系列讲座(1):BeginInvoke和EndInvoke方法
一.C#线程概述 在操作系统中一个进程至少要包含一个线程,然后,在某些时候需要在同一个进程中同时执行多项任务,或是为了提供程序的性能,将要执行的任务分解成多个子任务执行.这就需要在同一个进程中开启多个 ...
- [转]BeginInvoke和EndInvoke方法浅析
开发语言:C#3.0 IDE:Visual Studio 2008 一.C#线程概述 在操作系统中一个进程至少要包含一个线程,然后,在某些时候需要在同一个进程中同时执行多项任务,或是为了提 ...
- C# 对委托的BeginInvoke,EndInvoke 及Control 的BeginInvoke,EndInvoke 的理解
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- delegate 中的BeginInvoke和EndInvoke方法
开发语言:C#3.0 IDE:Visual Studio 2008 一.C#线程概述 在操作系统中一个进程至少要包含一个线程,然后,在某些时候需要在同一个进程中同时执行多项任务,或是为了提供程序的性能 ...
随机推荐
- Asp.net MVC 4 异步方法
今天我们来看一下,同样功能在 Asp.net MVC 4 下的实现,基于.net framework 4.5 下的async支持,让我们的代码更加简单,看下面片断代码名叫Index的Action方法: ...
- [转] Attach、Detach和DeleteObject
原文:Attach.Detach和DeleteObject,想飞的梦想 1.CWnd Attatch和Detach的关系 首先,要明白Windows对象和MFC对象的区别. MFC对象实际上并没有把整 ...
- 结构型:代理模式 Vs 适配器模式 Vs 门面模式(外观模式)
先上UML图 代理模式: 适配器模式: 门面模式(外观模式): 打了例子……呃……举个比方 代理模式: 水浒街,西门庆看上潘金莲,想和她嘿咻嘿咻,但是自己有不能去找潘金莲去说,于是他找到了金牌代理人王 ...
- 《Python基础教程(第二版)》学习笔记 -> 第一章 基础知识
写笔记的原因:书也看了一遍,视频也看了,但总是感觉效果不好,一段时间忘记了,再看又觉得有心无力,都是PDF的书籍,打开了就没有心情了,上班一天了,回家看这些东西,真的没多大精力了,所以,我觉得还是把p ...
- Selenium-Python学习——通过XPath定位元素
用Xpath定位元素的方法总是记不住,经常要翻出各种文档链接参考,干脆把需要用到的内容整到这个笔记中方便查找. Xpath是在XML文档中定位节点的语言.使用 XPath 的主要原因之一是当想要查找的 ...
- Selenium2Library系列 keywords 之 _SelectElementKeywords 之_get_select_list_options(self, select_list_or_locator)
def _get_select_list_options(self, select_list_or_locator): if isinstance(select_list_or_locator, Se ...
- eclipse 项目报错问题
所有的问题在windoes-->show view--->Problems里查看
- hive 配置mysql元数据库
在 hive的配置文件hive-site.xml中 <?xml version="1.0"?> <!-- Licensed to the Apache Softw ...
- leetcode@ [22]Generate Parentheses (递归 + 卡特兰数)
https://leetcode.com/problems/generate-parentheses/ Given n pairs of parentheses, write a function t ...
- 秒杀 ILSpy 等反编译利器 DotNet Resolver
http://dotnetresolver.eu5.org/downloads.html DotNet Resolver is a free .NET decompiler written in C# ...