Merge pull request #5714 from alexischr/update_bockbuild
[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                         for (int i = 0; i < 100; ++i) {
13                                 if (frame_count != 0)
14                                         break;
15                                 System.Threading.Thread.Sleep(100);
16                         }
17                         /*
18                          * seems to be broken
19                         while (!res.IsCompleted) {
20                                 System.Threading.Thread.Sleep(20);
21                         };
22                         IPHostEntry ip = Dns.EndGetHostEntry (res);
23                         Console.WriteLine (ip);*/
24                         if (frame_count < 1)
25                                 return 1;
26
27                         // A test for #444383
28                         AppDomain.CreateDomain("1").CreateInstance(typeof (Class1).Assembly.GetName ().Name, "Class1");
29
30                         return 0;
31                 }
32                 
33                 public static void ResolveCallback(IAsyncResult ar)
34                 {
35                     Console.WriteLine("ResolveCallback()");
36                     StackTrace st = new StackTrace();
37                     frame_count = st.FrameCount;
38                     for(int i = 0; i < st.FrameCount; i++) {
39                         StackFrame sf = st.GetFrame(i);
40                         Console.WriteLine("method: {0}", sf.GetMethod());
41                     }
42                     Console.WriteLine("ResolveCallback() complete");
43                 }
44         }
45
46 public class Class1
47 {
48         public Class1 () {
49                 AppDomain.CreateDomain("2").CreateInstance(typeof (Class1).Assembly.GetName ().Name, "Class2");
50         }
51 }
52
53 public class Class2
54 {
55         public Class2 () {
56                 new StackTrace(true);
57         }
58 }