2008-12-08 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mono / tests / stackframes-async.2.cs
1 using System;
2 using System.Net;
3 using System.Diagnostics;
4
5         class MainClass
6         {
7                 static int frame_count = 0;
8                 public static int Main(string[] args)
9                 {
10                         AsyncCallback cback = new AsyncCallback(ResolveCallback);
11                         IAsyncResult res = Dns.BeginGetHostEntry("localhost", cback, null);
12                         System.Threading.Thread.Sleep(2000);
13                         /*
14                          * seems to be broken
15                         while (!res.IsCompleted) {
16                                 System.Threading.Thread.Sleep(20);
17                         };
18                         IPHostEntry ip = Dns.EndGetHostEntry (res);
19                         Console.WriteLine (ip);*/
20                         if (frame_count < 1)
21                                 return 1;
22
23                         // A test for #444383
24                         AppDomain.CreateDomain("1").CreateInstance(typeof (Class1).Assembly.GetName ().Name, "Class1");
25
26                         return 0;
27                 }
28                 
29                 public static void ResolveCallback(IAsyncResult ar)
30                 {
31                     Console.WriteLine("ResolveCallback()");
32                     StackTrace st = new StackTrace();
33                     frame_count = st.FrameCount;
34                     for(int i = 0; i < st.FrameCount; i++) {
35                         StackFrame sf = st.GetFrame(i);
36                         Console.WriteLine("method: {0}", sf.GetMethod());
37                     }
38                     Console.WriteLine("ResolveCallback() complete");
39                 }
40         }
41
42 public class Class1
43 {
44         public Class1 () {
45                 AppDomain.CreateDomain("2").CreateInstance(typeof (Class1).Assembly.GetName ().Name, "Class2");
46         }
47 }
48
49 public class Class2
50 {
51         public Class2 () {
52                 new StackTrace(true);
53         }
54 }