[Gtk-sharp-list] Window refresh problem

Butler, Jennifer M. JenniferB@xetron.com
Thu, 7 Oct 2004 08:47:51 -0400


Hello all - 

I'm having a problem getting the gui that I'm working on to refresh
correctly. I have a background thread running that periodically needs to
update status information on the gui. My problem is that the gui is only
refreshing the screen when I move the mouse over it. What I really need is
for the gui to automatically refresh whenever it is updated (or updates
itself based on receiving an event from the worker thread).

I've seen some posts suggesting ThreadNotify as a solution for similar
problems. If I create a ThreadNotify instance and call WakeupMain on it, it
does fire the method correctly, but the gui does not refresh until I move
the mouse.

I've also tried calling QueueDraw from within the ThreadNotify method (on
both the main window and on the TextView that I would like to update) but
this also does not work.

Any suggestions would be much appreciated.

Thanks!



Some test code that I've been playing around with follows:

namespace Test {
	using System;
	using System.Threading;

	using Gtk;
	using Glade;
	using GtkSharp;

	public class Test
	{
		[Glade.Widget] private TextView textview1;
		[Glade.Widget] private Button button1;
		[Glade.Widget] private ProgressBar progressbar1;
		[Glade.Widget] private Window window1;

		private TextBuffer tb;

		private ThreadNotify tn;
		private Thread t;
		private int cnt = 0;

		// Constructor
		public Test()
		{
			Gtk.Application.Init();

			Glade.XML gxml = new Glade.XML (null, "test.glade",
"window1", null);
			gxml.Autoconnect (this);

			tb = new TextBuffer(null);
			textview1.Buffer = tb;
			tn = new ThreadNotify( new ReadyEvent(Ready) );
			t = new Thread(new ThreadStart(Fill) );
			t.IsBackground = true;

			Application.Run();
		}

		public void Fill()
		{
			int i = 0;
			for ( ; ; )
			{
				cnt = i;
				i = (i < 100) ? (i + 1) : 0;
				tn.WakeupMain();
			}
		}


		public void Ready()
		{
			tb.Insert(tb.EndIter, cnt.ToString() + "\n");
		}

		// DeleteWindow
		public void OnWindow1DeleteEvent (object o, DeleteEventArgs
args) 
		{
			t.Abort();
			Application.Quit ();
		}

		public void OnButton1Clicked(object o, EventArgs args)
		{
			t.Start();
			button1.Sensitive = false;
		}

		public static void Main()
		{
			Test t = new Test();
		}
	}
}