Asynchronous programming with delegates and CallBack
Asynchronous programming with delegate and CallBack using System; using System.Runtime.Remoting.Messaging; using System.Threading; namespace Memory_understanding { public delegate int myfundelegate(int num); class myMethod { public int myfun(int a) { Thread.Sleep(10000); return a*a; } } class program { public static void Main() { myMethod a = new myMethod(); myfundelegate d = new myfundelegate(a.myfun); IAsyncResult async = d.BeginInvoke(25, new AsyncCallback(mycallBackAsyn), "This from Main Thread"); Console.WriteLine("Processing the operations"); Console.ReadLine(); } private static void mycallBackAsyn(IAsyncResult ar) { AsyncResult a = (AsyncResult)ar; myfundelegate del = (myfundelegate)a.AsyncDelegate; int result = del.EndInvoke(ar);