2 // swf-control1.cs (based on swf-begininvoke.cs)
5 // Jackson Harper (jackson@ximian.com)
6 // Sebastien Pouliot <sebastien@ximian.com>
8 // Copyright (c) 2004-2005 Novell, Inc (http://www.novell.com)
12 using System.Diagnostics;
14 using System.Security;
15 using System.Security.Permissions;
16 using System.Threading;
17 using System.Windows.Forms;
19 namespace System.Windows.Forms {
21 public class BeginInvokeDemo : Form {
25 public BeginInvokeDemo ()
28 label.Dock = DockStyle.Fill;
29 label.TextAlign = ContentAlignment.MiddleCenter;
33 private void InfoUpdaterAllow ()
35 string s = String.Format ("SecurityManager.SecurityEnabled: {0}{1}{2}{1}",
36 SecurityManager.SecurityEnabled, Environment.NewLine, DateTime.Now.ToLongTimeString ());
38 s += String.Format ("Wake up {0}!", Environment.UserName);
40 catch (SecurityException) {
41 s += "SecurityException";
47 Console.WriteLine ("Delegate: {0}\n{1}", Thread.CurrentThread.Name, new StackTrace ().ToString ());
50 private delegate void updater ();
52 private void InfoUpdaterDeny ()
57 private void UpdateLabelAllow ()
60 Console.WriteLine ("Allow: {0}", Thread.CurrentThread.Name);
62 while (counter++ < 10) {
64 label.BeginInvoke (new updater (InfoUpdaterAllow));
70 Console.WriteLine ("Application.Exit ();");
74 [EnvironmentPermission (SecurityAction.Deny, Read = "USERNAME")]
75 private void UpdateLabelDeny ()
78 Console.WriteLine ("Deny: {0}", Thread.CurrentThread.Name);
80 while (counter++ < 10) {
82 label.BeginInvoke (new updater (InfoUpdaterDeny));
88 Console.WriteLine ("Application.Exit ();");
92 static bool debug = false;
93 static int counter = 0;
95 public static void Main (string[] args)
97 Thread.CurrentThread.Name = "Main";
98 BeginInvokeDemo demo = new BeginInvokeDemo ();
101 ThreadStart thread_start = new ThreadStart (demo.UpdateLabelDeny);
102 if (args.Length > 0) {
104 if (args [0] == "allow") {
105 thread_start = new ThreadStart (demo.UpdateLabelAllow);
108 Thread worker = new Thread (thread_start);
109 worker.Name = "Updater";
110 worker.IsBackground = true;
113 Application.Run (demo);