Jun 20, 2007

delegate asyn call

class Program
{
            static void Main()
            {
            AsyncCallback callback = new AsyncCallback(Callback);
            Func f = Console.ReadLine;
            f.BeginInvoke(Callback, null);
            Thread.Sleep(Timeout.Infinite);
            }

            static void Callback(IAsyncResult result)
            {
            AsyncResult async = result as AsyncResult;
            Func f = async.AsyncDelegate as Func;
            string s = f.EndInvoke(result);
            Console.WriteLine(s);
            Environment.Exit(0);
            }
}