zoukankan      html  css  js  c++  java
  • .net3.5后新增的 BeginInvoke EndInvoke 异步操作

            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 1;
            }
            protected void Main ()
            {
                //首先定义一个方法的封装..后边的LongTimeMethod是被封装的方法..
                Func<int> longTimeAction = new Func<int>(LongTimeMethod);
                //定义一个异步操作.. asynResult  
                //用上边的longTimeAction封装 来开启这个异步操作..
    
                int ss=0;
                IAsyncResult asynResult = longTimeAction.BeginInvoke((result) => { ss = longTimeAction.EndInvoke(result); }, null);
                //在上边的开启异步操作后..程序会另外启动一个线程来执行前边的封装方法..这个方法是委托给这个新线程的
                //得到了异步请求的结果..返回给 ss
            }
    
            int LongTimeMethod()
            {
                return 1;
            }
  • 相关阅读:
    MVC学习中遇到问题
    静态类和单例模式区别
    类或方法名后加<>
    MVC5入门
    开发BI系统时的需求分析研究
    BI项目需求分析书-模板
    商业智能学习系统
    数据库设计三大范式[转]
    BW对应后台表[转]
    SQL优化方案
  • 原文地址:https://www.cnblogs.com/iiwen/p/4835611.html
Copyright © 2011-2022 走看看