[Gtk-sharp-list] Thread-safe GUI update

Leon Stringer leon.stringer at ntlworld.com
Thu Mar 22 16:31:47 EDT 2007


Hi,

I'm updating a list (TreeView with TreeStore) from a thread when 
processing some items, something like:

while (Messages.Count > 0) {
	msg = (Message) Messages.Dequeue();
	send(msg);

         Gtk.Application.Invoke(delegate {
		treeStore.AppendAvalues(msg.To, msg.Text);
	});

	Thread.Sleep(0);
}

There's another thread adding messages to the message queue.

The problem is that sometimes the Gtk.Application.Invoke() is executed 
after I've dequeued the next message so the wrong item is added to the 
list. I could stick a greater value in Thread.Sleep() but this would be 
a kludge. Is there any thread-safe way to do this?

(Mono 1.1.13.8 for Windows)

Thanks in advance,

Leon...


More information about the Gtk-sharp-list mailing list