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:

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

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>
                                   http://www.skamphausen.de
Novel Science International GmbH
____________________________________________________________

Postfach    2944                 Tel:   +49 551 / 50 41 6- 0
37019 Goettingen                 Fax:   +49 551 / 50 41 6-99
Germany                          http://www.novelscience.com





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