On 1/6/07, White Spirit <[EMAIL PROTECTED]> wrote:
> Matteo Bertozzi wrote:
> > Why OnButtonClick() Code Freeze the GUI?
> > and how i could correct it?
>
> The problem is here:
>
> > Gtk.Application.Invoke (delegate {
> > Thread.Sleep(1800 + 3600);
> > button.Label = "End Hard Work";
> > });
Yes, the problem is there.
> The code in the event handler is already running in the GTK thread.
> Your code attempts to pass the code to the GTK thread from within the
> GTK thread.
>
> Gtk.Application.Invoke is only used within threads other than the GTK
> thread (because GTK# is not 'threadsafe'). So, if you had a thread
> called mythread, once that thread was started you would use
> Gtk.Application.Invoke to access GTK objects safely.
In fact, you can use Gtk.Application.Invoke everywhere. As you said,
he's already on the GTK's thread, so Gtk.Application.Invoke just
executes the code right away.
The problem, in fact, is that he is using Thread.Sleep in the GTK's
thread, so this blocks the UI. If this sleep is simulating some work
being done, it should be put on a different thread like this:
// UNTESTED
Thread worker = new Thread(delegate {
Thread.Sleep(1800 + 3600);
// We're on a different thread, Gtk.Application.Invoke is mandatory
Gtk.Application.Invoke(delegate {
button.Label = "End Hard Work";
});
});
worker.Start();
--
Felipe.
_______________________________________________
Gtk-sharp-list maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list