异步委托获取返回値

学习下面代码,有点意思

            Func<int, int> v = n=> {
                Thread.Sleep(1000);
                return n;
            };

           var ar= v.BeginInvoke(100,null,null);
            Console.WriteLine("main");
            while (ar.IsCompleted == false)
            {
                Console.Write(".");
            }
            var a = v.EndInvoke(ar);
            Console.WriteLine("over");

            Console.ReadKey();

 

posted @ 2017-04-17 21:23  lunawzh  阅读(202)  评论(0编辑  收藏  举报