- using System;
- using System.Threading;
- namespace ConsoleApplication1
- {
- class Class1
- {
-
- public delegate void AsyncEventHandler();
-
-
- void Event1()
- {
- Console.WriteLine("Event1 Start");
- System.Threading.Thread.Sleep(4000);
- Console.WriteLine("Event1 End");
- }
-
- void Event2()
- {
- Console.WriteLine("Event2 Start");
- int i = 1;
- while (i < 10)
- {
- i = i + 1;
- Console.WriteLine("Event2 " + i.ToString());
- }
- Console.WriteLine("Event2 End");
- }
- void Event3()
- {
- Console.WriteLine("Event3 Start");
- for (int i = 0; i < 100; i++)
- {
- Thread.Sleep(5);
- Console.WriteLine(i.ToString());
- }
- Console.WriteLine("Event3 End.");
- }
-
- [STAThread]
- static void Main(string[] args)
- {
- long start = 0;
- long end = 0;
- Class1 c = new Class1();
- Console.WriteLine("ready");
- start = DateTime.Now.Ticks;
-
- AsyncEventHandler asy = new AsyncEventHandler(c.Event1);
-
- IAsyncResult ia = asy.BeginInvoke(null, null);
-
- c.Event2();
-
-
- asy.EndInvoke(ia);
-
-
-
-
- end = DateTime.Now.Ticks;
- Console.WriteLine("时间刻度差=" + Convert.ToString(end - start));
- Console.ReadLine();
- }
- }
- }
posted @
2016-06-27 09:19
从未被超越
阅读(
258)
评论()
编辑
收藏
举报