async

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Xml.Linq;

namespace rooxml
{

    public class main
    {
        public delegate void AsyncEventHandler ();
        [STAThread]
        public static void Main ()
        {
            main m = new main ();
            AsyncEventHandler asy = new AsyncEventHandler(m.Event1);
            IAsyncResult ia = asy.BeginInvoke (null, null);

            m.Event2 ();
            asy.EndInvoke (ia);

        }

        void CallbackMathod(AsyncEventHandler ar){

        }

        void Event1(){
            Console.WriteLine ("e1 is start");
            System.Threading.Thread.Sleep (2000);
            Console.WriteLine ("e1 is end");
        }

        void Event2(){
            Console.WriteLine ("e2 is start");
            int i = 1;
            while (i < 1000) {
                i++;
                Console.WriteLine (i.ToString());
            }
            Console.WriteLine ("e2 is end");
        }

    }
}

 

posted @ 2015-05-23 21:07  Cvjar  阅读(154)  评论(0)    收藏  举报