In .:
[mono.git] / mono / tests / cas / threads / timer2.cs
1 using System;
2 using System.Reflection;
3 using System.Security;
4 using System.Security.Permissions;
5 using System.Timers;
6
7 class Program {
8
9         static void ShowStackTrace (object o, ElapsedEventArgs e)
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.AutoReset = false;
29                         t.Enabled = false;
30                 }
31         }
32
33         static bool debug;
34         static int counter = 0;
35         static int result = 0;
36         static Timer t;
37
38         // this Deny will prevent the Assembly.Evidence property from working
39         [SecurityPermission (SecurityAction.Deny, ControlEvidence = true)]
40         static int Main (string[] args)
41         {
42                 debug = (args.Length > 0);
43                 if (debug) {
44                         SecurityManager.SecurityEnabled = (args [0] != "off");
45                 }
46
47                 if (SecurityManager.SecurityEnabled) {
48                         Console.WriteLine ("SecurityManager.SecurityEnabled: true");
49                         ShowStackTrace (null, null);
50                 } else {
51                         Console.WriteLine ("SecurityManager.SecurityEnabled: false");
52                 }
53
54                 t = new Timer (500);
55                 t.Elapsed += new ElapsedEventHandler (ShowStackTrace);
56                 t.AutoReset = true;
57                 t.Enabled = true;
58                 
59                 System.Threading.Thread.Sleep (5000);
60                 return result;
61         }
62 }