Example #1
0
        static void Main(string[] args)
        {
            var c = new Program();

            Console.WriteLine("ready");
            var start = DateTime.Now.Ticks;

            //实例委托
            var asy = new AsyncEventHandler(c.Event1);
            //异步调用开始,没有回调函数和AsyncState,都为null
            var ia = asy.BeginInvoke(null, null);

            //同步开始,
            c.Event2();
            //异步结束,若没有结束,一直阻塞到调用完成,在此返回该函数的return,若有返回值。


            asy.EndInvoke(ia);

            //都同步的情况。
            //c.Event1();
            //c.Event2();

            var end = DateTime.Now.Ticks;

            Console.WriteLine("时间刻度差=" + Convert.ToString(end - start));
            Console.ReadLine();
        }
Example #2
0
        public void Callback(IAsyncResult result)
        {
            AsyncEventHandler handler = (AsyncEventHandler)((AsyncResult)result).AsyncDelegate;

            Util.Debuglog("result=" + handler.EndInvoke(result), "AsyEventClass.txt");
        }