protected void Main()
{
//首先定义一个方法的封装..后边的LongTimeMethod是被封装的方法..
Func<int> longTimeAction = new Func<int>(LongTimeMethod);
//定义一个异步操作.. asynResult
//用上边的longTimeAction封装 来开启这个异步操作.. IAsyncResult asynResult = longTimeAction.BeginInvoke(null, null);
//在上边的开启异步操作后..程序会另外启动一个线程来执行前边的封装方法..这个方法是委托给这个新线程的
//得到了异步请求的结果..返回给 ret
int ret = longTimeAction.EndInvoke(asynResult);
} int LongTimeMethod()
{
return ;
}
        protected void Main ()
{
//首先定义一个方法的封装..后边的LongTimeMethod是被封装的方法..
Func<int> longTimeAction = new Func<int>(LongTimeMethod);
//定义一个异步操作.. asynResult
//用上边的longTimeAction封装 来开启这个异步操作.. int ss=;
IAsyncResult asynResult = longTimeAction.BeginInvoke((result) => { ss = longTimeAction.EndInvoke(result); }, null);
//在上边的开启异步操作后..程序会另外启动一个线程来执行前边的封装方法..这个方法是委托给这个新线程的
//得到了异步请求的结果..返回给 ss
} int LongTimeMethod()
{
return ;
}

.net3.5后新增的 BeginInvoke EndInvoke 异步操作的更多相关文章

  1. 多线程 异步 beginInvoke EndInvoke 使用

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

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

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

  3. 转:C# 对委托的BeginInvoke,EndInvoke 及Control 的BeginInvoke,EndInvoke 的理解

    转载自:http://www.cnblogs.com/easyfrog/p/3141269.html using System; using System.Collections.Generic; u ...

  4. 用python+selenium登录cnblog后新增文章后再次删除该文章

    目的:登录cnblog后新增文章后再次删除该文章并验证 代码如下: #coding: utf-8 from selenium import webdriver from time import sle ...

  5. C#如何使用异步编程【BeginInvoke/EndInvoke】

    怎么使用异步,就是用委托进行处理,如果委托对象在调用列表中只有一个方法,它就可以异步执行这个方法.委托类有两个方法,叫做BeginInvoke和EndInvoke,它们是用来异步执行使用. 异步有三种 ...

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

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

  7. 织梦(dedecms)如何清空全部文章和删除后新增文章id号归1的方法

    很多朋友在使用织梦程序做网站的过程中,难免需要添加一些测试文章用于测试网站功能模板等,还有些人朋友网站改版需要变更内容的时候,面对着众多的老文章后总是一筹莫展! 由于织梦后台并不自带一键删除整站文章的 ...

  8. c#委托中的同步和异步方法即BeginInvoke和EndInvoke

    学习多线程之前我们先了解一下电脑的一些概念,比如进程,线程,这个参考https://www.cnblogs.com/loverwangshan/p/10409755.html 这篇文章.今天我们接着来 ...

  9. 异步编程(AsyncCallback委托,IAsyncResult接口,BeginInvoke方法,EndInvoke方法的使用小总结)

    http://www.cnblogs.com/panjun-Donet/archive/2009/03/03/1284700.html 让我们来看看同步异步的区别: 同步方法调用在程序继续执行之前需要 ...

随机推荐

  1. 【板子】gcd、exgcd、乘法逆元、快速幂、快速乘、筛素数、快速求逆元、组合数

    1.gcd int gcd(int a,int b){ return b?gcd(b,a%b):a; } 2.扩展gcd )extend great common divisor ll exgcd(l ...

  2. 你所不知道的Android Studio调试技巧

    转载:http://www.jianshu.com/p/011eb88f4e0d Android Studio目前已经成为开发Android的主要工具,用熟了可谓相当顺手.作为开发者,调试并发现bug ...

  3. 【codevs1993】 草地排水

    http://codevs.cn/problem/1993/ (题目链接) 题意 求有向图最大流. Solution Dinic. 代码 // codevs1993 #include<algor ...

  4. 【bzoj2038】 小Z的袜子(hose)

    http://www.lydsy.com/JudgeOnline/problem.php?id=2038 (题目链接) 转自:http://blog.csdn.net/bossup/article/d ...

  5. C# 调用api的方法

    问题场景: ASP.NET MVC Web API 定义 Post 方法,HttpClient 使用 JsonConvert.SerializeObject 传参进行调用,比如 Web Api 中定义 ...

  6. python图形界面(GUI)设计

    不要问我为什么要用 python 来做这种事,我回到“高兴咋地”也不是不可以,总之好奇有没有好的解决方案.逛了一圈下来,总体上来说,python 图形界面有以下几个可行度比较高的解决方案. 1. py ...

  7. type parameters of <T>T cannot be determined; no unique maximal instance exists for type variable T with upper bounds int,java.lang.Object

    今天在进行代码检查的时候出现下面的异常: type parameters of <T>T cannot be determined; no unique maximal instance ...

  8. Android中如何像 360 一样优雅的杀死后台Service而不启动

    http://my.oschina.net/mopidick/blog/277813 目录[-] 一.已知的 kill 后台应用程序的方法 方法: kill -9 pid 二.终极方法,杀死后台ser ...

  9. Linux Basic --- The First Character in The File Properity

    -rw-r--r-- [d]: content [-]: file [l]: link file [b]: interface device for storage in a device file ...

  10. html代码规范

    HTML代码规范   我们知道,前端工程师入门容易,通过学习基本的HTML和CSS就能在浏览器上看到实际的效果,可是要写好的HTML,就不是那么容易了.这里将和大家分享HTML规范,希望大家读完之后都 ...