[runtime] Overwrite stacktrace for exception on re-throw. Fixes #1856.
[mono.git] / mono / tests / cas / threads / timer1.cs
1 using System;
2 using System.Reflection;
3 using System.Security;
4 using System.Security.Permissions;
5 using System.Threading;
6
7 class Program {
8
9         static void ShowStackTrace (object o)
10         {
11                 if (debug)
12                         Console.WriteLine ("{0}: {1}", counter, Environment.StackTrace);
13
14                 try {
15                         Console.WriteLine (Assembly.GetExecutingAssembly ().Evidence.Count);
16                         result = 1;
17                 }
18                 catch (SecurityException se) {
19                         if (debug)
20                                 Console.WriteLine ("EXPECTED SecurityException {0}", se);
21                 }
22                 catch (Exception ex) {
23                         Console.WriteLine ("UNEXPECTED {0}", ex);
24                         result = 1;
25                 }
26
27                 if (counter++ > 5) {
28                         t.Dispose ();
29                 }
30         }
31
32         static bool debug;
33         static int counter = 0;
34         static int result = 0;
35         static Timer t;
36
37         // this Deny will prevent the Assembly.Evidence property from working
38         [SecurityPermission (SecurityAction.Deny, ControlEvidence = true)]
39         static int Main (string[] args)
40         {
41                 debug = (args.Length > 0);
42                 if (debug) {
43                         SecurityManager.SecurityEnabled = (args [0] != "off");
44                 }
45
46                 ShowStackTrace (null);
47
48                 TimerCallback cb = new TimerCallback (ShowStackTrace);
49                 t = new Timer (cb, null, 500, 1000);
50
51                 Thread.Sleep (5000);
52                 return result;
53         }
54 }