[Gtk-sharp-list] ThreadNotify Problem Under Windows

Archie Maskill galepsus at gmail.com
Tue Oct 18 11:41:35 EDT 2005


Hi everyone -

I'm sure this must be a known issue, but I've had no luck finding a
solution. I'm using Mono-1.1.9.2 on Windows 2000. I've found the
ThreadNotify.WakeupMain() method works, but not in a timely fashion. If I
set the ReadyEvent delegate to be a method that alters the appearance of a
widget, the widget's appearance will not change until the mouse has been
moved within the application window.

I've included some sample code below. It's very simple: click the button and
a worker thread does 4 seconds of "work", changing the colour of the label
(using ThreadNotify.WakeupMain). Under Linux this works with no problems.
Under Windows 2000, the text does not change colour until the mouse is moved
within the window. To see the effect simply click the button, move the mouse
outside the application's window, wait for the worker thread to finish (this
is indicated in the console), then move the mouse back into the application
window.

Has this been fixed in CVS? Or am I using it incorrectly? Or is there
something better I should be using?


Many thanks in advance!

-- Archie


using System.Collections;
using System.ComponentModel;
using Gtk;
using System.Threading;

public class MainClass
{
static Label lbl;
static ThreadNotify notify;

public static void Main()
{
Application.Init();
Window w = new Window("");
VBox v = new VBox();
w.Add(v);
Button b = new Button("Begin Test");
v.Add( b );
lbl = new Label("Some text");
lbl.ModifyFg( Gtk.StateType.Normal, new Gdk.Color(0xff,0,0) );
v.Add( lbl );
w.ShowAll();


notify = new ThreadNotify( new ReadyEvent(ColorButton) );
b.Clicked += new System.EventHandler( buttonClick );
Application.Run();
}

static void buttonClick( object sender, System.EventArgs e )
{
new Thread( new ThreadStart( WorkerThread ) ).Start();
}

static void ColorButton()
{
System.Console.WriteLine("Coloring button green");
lbl.ModifyFg(Gtk.StateType.Normal, new Gdk.Color(0,0xff,0) );
}

static void WorkerThread()
{
System.Console.WriteLine("In worker thread");
Thread.Sleep(2000);
notify.WakeupMain();
Thread.Sleep(2000);
System.Console.WriteLine("Exiting worker thread");
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/gtk-sharp-list/attachments/20051018/8915d8d5/attachment.html


More information about the Gtk-sharp-list mailing list