Well, I’ve just spent way more time than necessary debugging an issue I had with a TreeView not being correctly updated and freezing the whole application.

Unlike WPF (and also I think Winforms), Gtk# does not complain when a GUI object is accessed or modified from a separate thread, so I incorrectly assumed that the issue wasn’t related to cross thread safety. As it turns out, my assumption was wrong (they usually are ;) ).

In order to alter Gtk object from a separate thread, a method similar to the WPF Dispatcher can be used:

Gtk.Application.Invoke(delegate {
      randomGtkWindow.Title = "blah";
});

Now, if we don’t invoke on the original Gtk thread, sometimes it will work, sometimes it won’t, with quite disastrous results. From what I’ve experienced so far, generally no error is thrown and if it is, then it’ll be quite cryptic.

Maybe the Gtk# developers should cause Gtk objects to throw an exception when accessed in a different thread?

Leave a Reply

You must be logged in to post a comment.