Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Test some of the mainloop features

svn path=/trunk/winforms/; revision=33978
  • Loading branch information...
commit 85e08c5785b54e1d1587b1d78bafd711f44a361f 1 parent e32b9a9
Jackson Harper authored
Showing with 107 additions and 0 deletions.
  1. +10 −0 mainloop/Makefile
  2. +97 −0 mainloop/swf-mainloop.cs
View
10 mainloop/Makefile
@@ -0,0 +1,10 @@
+all: mono
+
+mono: swf-mainloop.cs
+ mcs swf-mainloop.cs /r:System.Windows.Forms.dll /r:System.Drawing.dll
+
+dotnet: swf-mainloop.cs
+ csc swf-mainloop.cs /r:System.Windows.Forms.dll /r:System.Drawing.dll
+
+clean:
+ rm swf-mainloop.exe -r -f
View
97 mainloop/swf-mainloop.cs
@@ -0,0 +1,97 @@
+//
+// swf-mainloop.cs
+//
+// Author(s):
+// Jackson Harper (jackson@ximian.com)
+//
+// Copyright (c) 2004 Novell, Inc (http://www.novell.com)
+//
+
+using System;
+using System.Drawing;
+using System.Threading;
+using System.Windows.Forms;
+
+namespace System.Windows.Forms {
+
+ public class MainLoopDemo : Form {
+
+ private Label idle_label;
+ private Label begininvoke_label;
+ private Label timer_label;
+
+ public MainLoopDemo ()
+ {
+ SuspendLayout ();
+
+ idle_label = new Label ();
+ idle_label.Anchor = AnchorStyles.Left | AnchorStyles.Right;
+ idle_label.TextAlign = ContentAlignment.MiddleCenter;
+ idle_label.Text = "Idle";
+ Controls.Add (idle_label);
+
+ begininvoke_label = new Label ();
+ begininvoke_label.Anchor = AnchorStyles.Left | AnchorStyles.Right;
+ begininvoke_label.Top = idle_label.Bottom + 10;
+ begininvoke_label.TextAlign = ContentAlignment.MiddleCenter;
+ begininvoke_label.Text = "begininvoke";
+ Controls.Add (begininvoke_label);
+
+ timer_label = new Label ();
+ timer_label.Anchor = AnchorStyles.Left | AnchorStyles.Right;
+ timer_label.Top = begininvoke_label.Bottom + 10;
+ timer_label.TextAlign = ContentAlignment.MiddleCenter;
+ timer_label.Text = "timer";
+ Controls.Add (timer_label);
+
+ ResumeLayout ();
+ }
+
+ private delegate void updater ();
+
+ private void UpdateLabel ()
+ {
+ while (true) {
+ lock (this) {
+ begininvoke_label.BeginInvoke (new updater (DateUpdater));
+ }
+ Thread.Sleep (500);
+ }
+ }
+
+ private void DateUpdater ()
+ {
+ begininvoke_label.Text = "BeginInvoke: " + DateTime.Now.ToLongTimeString ();
+ }
+
+ private void TimerUpdater (object sender, EventArgs e)
+ {
+ timer_label.Text = "Timer: " + DateTime.Now.ToLongTimeString ();
+ }
+
+ private void IdleHandler (object sender, EventArgs e)
+ {
+ idle_label.Text = "Idle: " + DateTime.Now.ToLongTimeString ();
+ }
+
+ public static void Main ()
+ {
+ MainLoopDemo demo = new MainLoopDemo ();
+
+ ThreadStart thread_start = new ThreadStart (demo.UpdateLabel);
+ Thread worker = new Thread (thread_start);
+ worker.IsBackground = true;
+ worker.Start();
+
+ Timer t = new Timer ();
+ t.Interval = 250;
+ t.Tick += new EventHandler (demo.TimerUpdater);
+ t.Enabled = true;
+
+ Application.Idle += new EventHandler (demo.IdleHandler);
+
+ Application.Run (demo);
+ }
+ }
+}
+
Please sign in to comment.
Something went wrong with that request. Please try again.