Re: Updating GUI during long operation
- From: Allin Cottrell <cottrell wfu edu>
- To: Kip Warner <kip thevertigo com>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Updating GUI during long operation
- Date: Thu, 25 Apr 2013 22:53:11 -0400 (EDT)
On Thu, 25 Apr 2013, Kip Warner wrote:
I will try adjusting the animation's framerate and seeing if I can
get the worker thread to give a breather to the main thread which
seems to be working when using an idle_add() callback to trigger
an event flush.
I have a situation which might, perhaps, be akin to yours. From the
GUI, my app calls an iterative numerical procedure that can be quite
time consuming. Without any special treatment, this causes the GUI
to appear "frozen" and unresponsive, as if something had gone wrong.
My solution was to introduce a "breather", as you call it. I
installed a callback function, to be called every k iterations of
the numerical procedure (for a suitable value of k). The callback
simply looks like this:
static void gui_show_activity (void)
{
while (gtk_events_pending()) {
gtk_main_iteration();
}
}
If my app is not operating in GUI mode the callback function pointer
is NULL and is skipped; if it's in GUI mode the callback ensures
that a spinner operates and the GUI doesn't look dead. I'm not doing
anything fancy with threads; just every so many rounds of the
numerical operation this callback is triggered, and it stops the GUI
from looking dead.
Inside the numerical procedure I have something like
if (iter % k == 0 && activity_callback != NULL) {
activity_callback();
}
Allin Cottrell
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]