[Gtk-sharp-list] GTK# app "hanging"

Manuel Capinha Manuel Capinha <mcapinha@gmail.com>
Tue, 22 Feb 2005 16:48:48 +0000


Thanks Francisco and Jonathan!

This was exactly my problem. I now recall having read about this
somewhere but it had totally slipped my mind. I did a quick code
rework (basically just pasting my threaded code into the main
function) and the hangs are no more!

Thanks once again,
Manuel


On Tue, 22 Feb 2005 06:54:42 -0500, Jonathan Pryor <jonpryor@vt.edu> wrote:
> On Tue, 2005-02-22 at 10:46 +0000, Manuel Capinha wrote:
> > The watcher object is threaded and is responsible for updating the
> > images. This is done by creating a WebRequest object that points to
> > the image in a webserver. The Gdk.Image object is updated with:
> >
> >     image.Pixbuf = new Gdk.Pixbuf(request.GetResponse().GetResponseStream());
> 
> Assuming that the thread that executes the above is NOT your GUI thread,
> that is your problem. :-)
> 
> In GTK+/Gtk#, you can only update the GUI from the GUI thread.  All
> other threads MUST NOT modify the GUI, as this will cause random hangs
> (like you're seeing).
> 
> The solution is to add a callback to the GUI thread which will update
> the GUI.  Callbacks can be added via GLiub.Timeout.Add.
> 
> In C# 2.0, you could do:
> 
>         Stream stream = request.GetResponse().GetResponseStream();
>         GLib.Timeout.Add (0, delegate {
>                 image.Pixbuf = new Gdk.Pixbuf (stream);
>         });
> 
> C# 1.1 implementations are left as a problem for the reader. :-)
> 
>  - Jon
> 
>