Exemplo n.º 1
0
        static void Mycallback(IAsyncResult ir)
        {
            MathDelegate d      = ir.AsyncState as MathDelegate;
            long         result = d.EndInvoke(ir);

            Console.WriteLine("result=" + result);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            MathClass math = new MathClass();

            MCDelegate del = new MCDelegate(math.M1);

            del += new MCDelegate(MathClass.M2);

            del += new MCDelegate(math.M1);

            del();
            del -= new MCDelegate(math.M1);
            del();

            MathDelegate del1, del2;

            del1 = new MathDelegate(math.Add);

            del2 = new MathDelegate(MathClass.Multiply);

            //MyInovoke(del1);

            AsyncCallback mycallback = delegate(IAsyncResult ir)
            {
                long result = del1.EndInvoke(ir);

                Console.WriteLine($"The add result done async is {result}");
            };

            IAsyncResult iar = del1.BeginInvoke(111, 333, mycallback, null);

            Console.WriteLine(del2.Invoke(333, 455));


            Console.ReadLine();
        }