[Gtk-sharp-list] Updating of a window not done right away

Michael Hutchinson m.j.hutchinson at gmail.com
Tue Sep 23 23:43:04 EDT 2008


On Tue, Sep 23, 2008 at 4:51 AM, Mathias Tausig <mtausig at fsmat.at> wrote:
> Hy!
>
> I wrote a class DisplayPanel (see below., which should just display some text right away. The problem is, it just doesn't do that if I start some blocking function after setting the text. If I execute
>
> Gtk.Window w = new Gtk.Window("Test");
> w.Show();
> for(int i=0;i<20;++i){
>        DisplayPanel dp = new DisplayPanel("",w);
>        dp.SetTitle(i);
>        Thread.Sleep(3000);
>        dp.Dispose();
> }
>
> sometimes it does display the correct text right away, but sometimes (rather unpredictable, about every third time) I get just an empty Window.
> Does anyone have an idea, what might cause this?

You're blocking the main loop. The main GTK loop handles repainting,
firing events, etc.

If you need to make blocking calls that will take a long time (or are
of indeterminate length), use asynchronous mechanisms. If you use
threads or .NET async calls, you will have to be careful to only touch
the UI from the GTK thread.

The following articles cover these topics:
http://msdn.microsoft.com/en-us/magazine/cc301332.aspx
http://www.mono-project.com/Responsive_Applications



-- 
Michael Hutchinson
http://mjhutchinson.com


More information about the Gtk-sharp-list mailing list