学无先后,达者为师

网站首页 编程语言 正文

beginInvke带回调函数使用

作者:彭先生zzZ 更新时间: 2022-08-13 编程语言
 static void Main(string[] args)
        {

            //AsnycRes_Dog dog = new AsnycRes_Dog();
            //var man = new Man(dog);
            //var thief = new Thief(dog);

            //dog.HappenEvent();
            //Console.ReadKey();


            //异步阻塞 通过endinvoke
            
            BeginInvoeUserTest be = new BeginInvoeUserTest();
            Program p = new Program();
            be.mutiDel = be.WaysToMuti;
            var Ways = be.mutiDel;
            IAsyncResult Result = Ways.BeginInvoke(10, 20, p.CWWAYS, null);
            while (!Result.IsCompleted)
            {
                Console.WriteLine("Runing .........");
                Thread.Sleep(500);
            }
            int Res = Ways.EndInvoke(Result);

            Console.WriteLine(Res);

            Console.ReadKey();

        }


        public void CWWAYS(IAsyncResult ir)
        {
            Console.WriteLine("计算完成了!!!");
        }
class BeginInvoeUserTest
    {
        public delegate int MutiNum(int a, int b);
        public MutiNum mutiDel;
        public int WaysToMuti(int a, int b)
        {
            int Result = a+b;
            for (int i = 0; i < 10; i++)
            {
                Thread.Sleep(500);
                Result += a;
            }
            return Result;
        }


    }

原文链接:https://blog.csdn.net/weixin_44035651/article/details/126307710

栏目分类
最近更新