Beispiel #1
0
        static void Main(string[] args)
        {
            Console.WriteLine(System.Threading.Thread.CurrentThread.ManagedThreadId);

            MathClass    mat = new MathClass();
            MathDelegate del1, del2;

            del2 = new MathDelegate(MathClass.Multiply);
            //Invoke(del2);

            //List<string> mystrings = new List<string>();
            //mystrings.Add("monday");
            //mystrings.Add("tuesday");
            //mystrings.Add("wednesday");
            //mystrings.Add("thursday");
            //mystrings.Add("friday");

            //Action<string> myaction = new Action<string>(Print);
            //mystrings.ForEach(myaction);

            //MyDelegate multicast;
            //multicast=new MyDelegate(mat.M1);
            //multicast+=new MyDelegate(MathClass.M2);
            //multicast.Invoke();


            del1 = new MathDelegate(mat.Add);
            //Console.WriteLine(del1.Invoke(111,99));
            IAsyncResult iar = del1.BeginInvoke(11, 9, new AsyncCallback(Mycallback), del1);

            ThreadPool.QueueUserWorkItem(M1);
            ThreadPool.QueueUserWorkItem(M1);
            ThreadPool.QueueUserWorkItem(M1);
            ThreadPool.QueueUserWorkItem(M2);


            Console.WriteLine("Main End");
            Console.ReadLine();
        }
Beispiel #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();
        }