All pastes #22196 Raw Edit

Unnamed

public text v1 · immutable
#22196 ·published 2005-09-05 22:50 UTC
rendered paste body
using System;
using System.Threading;
using Gtk;

namespace IdleEx
{
	class Driver
	{
		static Button GoButton;
		static TextView MsgText;

		static bool GtkSync_OtherThreadDone()
		{
			Console.WriteLine("GtkSync");

			GoButton.Sensitive = true;
			MsgText.Buffer.Text += "Got Done Message.\n";

			return false;
		}

		static void Job()
		{
			Thread.Sleep(3000);
			Console.WriteLine("OtherThread Posting a job.");
			GLib.Idle.Add(new GLib.IdleHandler(GtkSync_OtherThreadDone));
		}

		[STAThread]
		static void Main(string[] args) 
		{
			Application.Init();

			GoButton = new Button("Go!");
			GoButton.Clicked += new EventHandler(GoButton_Clicked);

			MsgText = new TextView();

			ScrolledWindow scroller = new ScrolledWindow();
			scroller.Add(MsgText);

			VBox vbox = new VBox(false, 5);
			vbox.PackStart(GoButton);
			vbox.PackStart(scroller);

			Window win = new Window("IdleEx");
			win.DeleteEvent += new DeleteEventHandler(win_DeleteEvent);
			win.Add(vbox);
			win.ShowAll();

			Application.Run();
		}

		private static void GoButton_Clicked(object sender, EventArgs e)
		{
			GoButton.Sensitive = false;
			Thread thr = new Thread(new ThreadStart(Job));
			thr.Start();
		}

		private static void win_DeleteEvent(object o, DeleteEventArgs args)
		{
			Application.Quit();
			args.RetVal = true;
		}
	}    
}