2005-04-21 Sebastien Pouliot <sebastien@ximian.com>
[mono.git] / mono / tests / cas / threads / thread3.cs
1 using System;
2 using System.Security;
3 using System.Security.Permissions;
4 using System.Threading;
5
6 class Program {
7
8         static void ThreadProc ()
9         {
10                 if (debug)
11                         Console.WriteLine (Environment.StackTrace);
12
13                 Thread.Sleep (1000);
14                 try {
15                         // this will work
16                         Environment.Exit (0);
17                         Console.WriteLine ("UNEXPECTED execution");
18                 }
19                 catch (SecurityException se) {
20                         Console.WriteLine ("UNEXPECTED SecurityException {0}", se);
21                 }
22         }
23
24         static bool debug;
25
26         // this Deny _WONT_ prevent Environment.Exit from working
27         // even if the Deny is executed prior to the call
28         [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
29         static int End ()
30         {
31                 Thread.Sleep (2000);
32                 return 1;
33         }
34
35         static int Main (string[] args)
36         {
37                 debug = (args.Length > 0);
38                 Thread t = new Thread (new ThreadStart (ThreadProc));
39                 t.Start ();
40
41                 return End ();
42         }
43 }