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

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


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();

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


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 for Windows)

Thanks in advance,


More information about the Gtk-sharp-list mailing list