The Main Loop and My Own Actions

Dear PerlHackers,

I've been searching the archive for an answer to this but found only
half the truth.

The problem is that I want to call some actions during the main event
loop such as updating a time-showing label and watching a file if it
has been changed since my last visit.

This is what I got right now:

while (1) {
  while (Gtk->events_pending) {
  # Update the Time Label 
  $time = strftime("%H:%M:%S",localtime());
  # Guess what...
  # FIXME: how to watch files and update time without causing 100%CPU??

As you can see from the FIXME line, this causes my programm to munch
every CPU circle it can get from the system which is really not
necessary. One update per second would be enough, but that
sleep(1)-line just makes the GUI respond very slow.

Obviously it has to be a major issue so I think I'm just missing some
point. In that case please forgive my humble question and please point
me to the appropriate documentation.

Thanks And Regards
Stefan Kamphausen              <kamphausen novelscience com>
Novel Science International GmbH

Postfach    2944                 Tel:   +49 551 / 50 41 6- 0
37019 Goettingen                 Fax:   +49 551 / 50 41 6-99

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