[Gtk-sharp-list] Gtk# & background threads

Christian Hoff christian_hoff at gmx.net
Sun Sep 14 14:59:45 EDT 2008

I'm not 100% sure, but I don't think that's possible. I got inconsistent 
behaviour when I tried to invoke any Gtk# method, not just the ones 
directly related to the GUI display.

But why do you want to do so? If your method is executed in a different 
thread, just use Gtk.Application.Invoke, a Gtk.ReadyEvent or 
Gdk.Threads.Enter before calling anything of Gtk and Gdk.Threads.Leave 
after these calls if you need your code to be executed at once. However, 
on Linux Gtk is relativly tolerant in most cases, you will maybe notice 
that your app just hangs a little and then everything goes on after you 
have moved the mouse; but if you find out you can call some Gtk 
functions from another thread, it is not guaranteed to work on Windows 
which is much more restrictive here :-) !

Adam Tauno Williams schrieb:
> I understand that all modifcations to the UI must be performed in the  
> "main" thread via Application.Invoke() or some such mechanism.
> But can widgets be created in another thread and then provided to the  
> main thread to be added to the UI?  Like:
> delegate Gtk.VBox SummaryLoader(Whitemice.ZOGI.Entity  entity,
> 		                IList<Whitemice.ZOGI.ObjectLink> links);
> ....
> Viewport viewport;
> viewport.Child = new Label("Loading links...");
> SummaryLoader loader = delegate(Whitemice.ZOGI.Entity  e,
> 	                        IList<Whitemice.ZOGI.ObjectLink> l)
> {
>    VBox 	 v = new VBox();
>    v.Spacing = 2;
>    foreach(Whitemice.ZOGI.ObjectLink link in l)
>    {
> 		... compose expensive widget (olf) ...
>      v.PackStart(olf, false, false, 2);
>    }
>    return v;
> };
> loader.BeginInvoke (entity, links, delegate (IAsyncResult r)
> {
>    viewport.Remove(viewport.Child);
>    viewport.Child = loader.EndInvoke(r);
> }, null);
> _______________________________________________
> 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