[runtime] Overwrite stacktrace for exception on re-throw. Fixes #1856.
[mono.git] / mono / tests / cas / threads / delegate1.cs
1 using System;
2 using System.Reflection;
3 using System.Security;
4 using System.Security.Permissions;
5 using System.Threading;
6
7 public class Program {
8
9         delegate void Test ();
10         
11         public static void TestStatic ()
12         {
13                 if (debug) {
14                         string name = Thread.CurrentThread.Name;
15                         if (name == null)
16                                 name = "[unnamed]";
17
18                         Console.WriteLine ("\tDelegate running on thread: {0} (from pool: {1})\n{2}", name, 
19                                 Thread.CurrentThread.IsThreadPoolThread, Environment.StackTrace);
20                 }
21
22                 try {
23                         Console.WriteLine (Assembly.GetExecutingAssembly ().Evidence.Count);
24                         result = 1;
25                 }
26                 catch (SecurityException se) {
27                         if (debug)
28                                 Console.WriteLine ("EXPECTED SecurityException {0}", se);
29                 }
30                 catch (Exception ex) {
31                         Console.WriteLine ("UNEXPECTED {0}", ex);
32                         result = 1;
33                 }
34         }
35
36         static bool debug;
37         static int result;
38
39         // this Deny will prevent the Assembly.Evidence property from working
40         [SecurityPermission (SecurityAction.Deny, ControlEvidence = true)]
41         public static int Main (string[] args)
42         {
43                 result = 0;
44                 debug = (args.Length > 0);
45                 if (debug) {
46                         Thread.CurrentThread.Name = "Main";
47                         Console.WriteLine (">Thread.Name: {0}", Thread.CurrentThread.Name);
48                 }
49
50                 Test t = new Test (TestStatic);
51                 IAsyncResult ar = t.BeginInvoke (null, null);
52                 t.EndInvoke (ar);
53
54                 if (debug)
55                         Console.WriteLine ("<Thread.Name: {0}", Thread.CurrentThread.Name);
56                 
57                 return result;
58         }
59 }