On Mon, Feb 23, 2009 at 8:44 AM, Rapha222 <raphaeljav...@gmail.com> wrote:
> GTK is thread safe, so you can't to modify Gtk Widgets from another thread
> that the thread which is running the MainLoop (Application.Run()), unless if
> you use Thread.Enter() and Thread.Leave() to stop the mainloop during the
> modifications.

I assume here you mean that it is not thread-safe.

Regardless, you can simulate this by using the provided Gtk.Application.Invoke:

void ThreadEntryPoint() {
    // do stuff...
    Application.Invoke(delegate {
        // do stuff with widgets
    });
    // do more stuff...
}

The call is not synchronous, and will return immediately.  The
delegate will be executed at some point later on the main thread.  If
you need a synchronous version:

void SynchronousInvoke(EventHandler e) {
    ManualResetEvent ev = new ManualResetEvent(false);

    Application.Invoke(delegate(object o, EventArgs args) {
        e(o, args);
        ev.Set();
    }

    ev.WaitOne();
}

It's not a terribly efficient method but if you're not making these
calls that often the performance should be fine.

-- 
Chris Howie
http://www.chrishowie.com
http://en.wikipedia.org/wiki/User:Crazycomputers
_______________________________________________
Gtk-sharp-list maillist  -  Gtk-sharp-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list

Reply via email to