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

Iñigo Illán Aranburu kodeport at terra.es
Thu Mar 22 17:28:34 EDT 2007


You must use synchronization mechanisms like shown here:
http://www.codersource.net/csharp_tutorial_multithreading.html


El jue, 22-03-2007 a las 20:31 +0000, Leon Stringer escribió:
> 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...
> _______________________________________________
> Gtk-sharp-list maillist  -  Gtk-sharp-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list



More information about the Gtk-sharp-list mailing list