[Gtk-sharp-list] Gtk.DrawingArea not thread-agnostic on Win32?

Adam Tauno Williams awilliam at whitemice.org
Tue Sep 23 06:56:37 EDT 2008


On Tue, 2008-09-23 at 12:00 +0200, Sam Hocevar wrote:
> I have a threaded GTK# application that creates widgets in several
> threads (all with proper synchronisation, of course). It works perfectly
> on Linux, but it hangs on Win32 when using Gtk.DrawingArea objects.

Yep, it is well documented that what you describe won't work.

>    Attached is a sample program which does the following:
>      - thread #1 creates a Gtk.Window
>      - thread #1 spawns thread #2
>      - thread #2 creates a Gtk.DrawingArea object
>      - thread #1 attaches the DrawingArea to the Window
>      - thread #1 waits for user input
>      - thread #2 destroys the Gtk.DrawingArea object
>      - thread #1 joins thread #2
>      - thread #1 exits
>    Everything goes well on Linux. On Win32, the program hangs during the
> Gtk.DrawingArea destruction.

This is expected;  Gtk on LINUX is much more tolerant that on Win32, but
even on LINUX it will crash eventually.

> It should be noted that using Gtk.Button instead of Gtk.DrawingArea
> makes everything work properly on both Linux and Windows.
> Any ideas on what may be wrong?

Management of the UI must all be done from the main thread.  I use
Application.Invoke(delegate{ }) to modify the UI from [potentially]
other threads.



More information about the Gtk-sharp-list mailing list