Re: [Vala] Problem with Thread, GTK and signals
- From: Jan Hudec <bulb ucw cz>
- To: Simon Arnaud <mazwak gmail com>
- Cc: vala-list gnome org
- Subject: Re: [Vala] Problem with Thread, GTK and signals
- Date: Tue, 29 Sep 2009 17:25:55 +0200
On Tue, Sep 29, 2009 at 16:06:44 +0200, Simon Arnaud wrote:
Hi
I'm trying to update 2 progress bars from a Thread emitting a progressed
signal.
The idea is the thread does some long running tasks, and updates a task
progress, and a total progress by emitting a signal.
And I update 2 progressbars when this signal is emitted.
You must not call Gtk functions from different thread. Ever.
You have to add an idle handler to the default context that will update the
progress-bars. So from your thread you do something like:
Idle.add(() => { update-progress-bars(); return false; });
The idle will execute once and than delete itself, because the closure
returns false.
Note: In linux it didn't work correctly either -- it has race-conditions and
can therefore crash randomly, even though rarely since the gui thread isn't
doing much.
Another note: GLib, GIO and GTK are designed so that you should not need to
use threads. The async functions in GIO allow you to do all filesystem and
network access from the event loop and since vala has support for async
functions, using the async GIO functions is now easy. Consider using that
instead of threads, it will make your life easier. Glib may actually
internally use threads for the operations, but you don't have to care about
the synchronization that way.
--
Jan 'Bulb' Hudec <bulb ucw cz>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]