[Gtk-sharp-list] I really need some sort of tutorial

Chris Howie cdhowie at gmail.com
Tue Jun 3 12:19:05 EDT 2008

On Tue, Jun 3, 2008 at 12:09 PM, Kenneth D Weinert
<kenw at quarter-flash.com> wrote:
> That's a problem - I *have* looked at that and I'm just not making the
> connection. For what you understand of my application, which one of
> those approaches would make most sense?

If you are familiar with threads, just use those.  (I do and it's not
too tricky.)

The main thing is that if you ever, *ever* touch the GUI from an
alternate thread you must actually do so from the main thread.  This
sounds contradictory, but it is in fact not.

First, all of the data that you are reading from your thread (in this
case the values in the entries) must be available to the thread
without needing access to the GUI objects.  So make a data structure
to hold them and parse them out on the *main* thread.  Pass these
parsed values to the thread (either with a ParameterizedThreadStart or
an anonymous delegate, etc).  This will ensure you don't read from the

Then, to write back updates to the GUI while it's running you need to
pass a delegate over to the main thread for invocation there.  The
simplest way is:

Application.Invoke(delegate { someEntry.Text = "foobar"; });

Or some such pattern.  You could create a wrapper class that does this
in the setters if you wanted.  Note that this will not work for
getters (since Invoke returns immediately) and besides you don't want
to do cross-thread communication for values you'll be using

Hope you can salvage some meaning from this.  :)

Chris Howie

More information about the Gtk-sharp-list mailing list