码迷,mamicode.com
首页 > 其他好文 > 详细

代理的简单使用

时间:2015-10-27 09:52:37      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:

 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("主线程方法结束");
        }

 

代理的简单使用

标签:

原文地址:http://www.cnblogs.com/wangchuang/p/4913259.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!