zoukankan      html  css  js  c++  java
  • 代理的简单使用 简单的异步

     static void Main(string[] args)
            {
                //DateTime dt = DateTime.Now;
                //RemoteObject.MyObject app = new RemoteObject.MyObject();
                //Console.WriteLine(app.ALongTimeMethod(1, 2, 1000));
                //Method();
                //Console.WriteLine("用了" + ((TimeSpan)(DateTime.Now - dt)).TotalSeconds + "秒");
                //Console.ReadLine();
    
                DateTime dt = DateTime.Now;
                RemoteObject.MyObject app = new RemoteObject.MyObject();
                MyDelegate md = new MyDelegate(app.ALongTimeMethod);
                IAsyncResult Iar = md.BeginInvoke(1, 2, 1000, null, null);
                Method();
                if (!Iar.IsCompleted)
                {
                    Console.WriteLine("没有结束");
                    Iar.AsyncWaitHandle.WaitOne();
                }
                else
                {
                    Console.WriteLine("结果是" + md.EndInvoke(Iar));
                }
                Console.WriteLine("用了" + ((TimeSpan)(DateTime.Now - dt)).TotalSeconds + "");
                Console.ReadLine();
            }
    
            private delegate int MyDelegate(int a, int b, int time);
            private static void Method()
            {
                Console.WriteLine("主线程方法开始");
                System.Threading.Thread.Sleep(3000);
                Console.WriteLine("主线程方法结束");
            }
  • 相关阅读:
    多态与鸭子类型
    mixin与派生
    4.9作业
    property
    继承
    封装
    《梦断代码》阅读笔记1
    阅读笔记3——《大道至简》第四、五、六章
    阅读笔记2——《大道至简》第二、三章
    阅读笔记1——《大道至简》第一章
  • 原文地址:https://www.cnblogs.com/wangchuang/p/4913259.html
Copyright © 2011-2022 走看看