Re: gtk app with threads



"Cristóvão B. B. Dalla Costa" said:
Hello

I'm creating an application which will download several large files.
I've setup a progress bar to display during the download and I wish to
keep it updated and not freeze the app display. I suppose threads are
the obvious choice and I've created a separate thread to download the
packages.

I suppose that I shouldn't mess with widgets from the second thread
since I've already caused several errors to come up working that way and
I'm currently attempting to install an idle handler on the main thread
to update the display.

gtk2-perl doesn't currently support perl ithreads fully (much at all) we now
have patches that will allow it to, but those will be in unstable releases for
quite a while for testing purposes etc. they should be cvs (and the next
unstable rel) very soon.

Problem is, the idle thread doesn't ever get called. I'm creating it as
such:

    Glib->idle_add (sub { $self->update_progress (\$downloaded) });

Where $downloaded is a shared variable.

Does anyone here have experience with this type of problem? How would
you recommend solving this particular design problem?

you need to return true to ensure that your idle handler stays installed. what
you have there will run once and then uninstall itself, thus making you think
that it never ran at all.

that being said using an idle is a bad idea, it is liable to peg your
processor. using a timeout with a small timeout value, 100, 250, 500 is a much
better approach. there are very few (i can think of none) situations where
idle is appropriate.

-- 
-rm



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]