Re: threads and trayicon error



anguila wrote:

so the mistake in my code is use threads?

Not necessarily. You can use threads, but you must not call any Gtk+ 
functions in the non-main thread (the one where Gtk->main was called). 
You called $pic->set_from_file($logo_off) in a thread.

I thought that maybe I used bad
some function :\ I will try with this way (mentioned in the gtk2-perl faq),
but it's weird that the trayicon changes good and after X (unknow) time
crash and this icon becomes a line :\ with any reason

I'am no thread expert, but once the internal data structures are messed
due to bad synchronized access I think everything can happen at any time
;)

Without threads the control flow should look like this:

  * main
    - init Gtk
    - build trayicon
    - create a timeout/interval callback (e.g. every 60s)
      to poll the website (with Glib::Timeout->add)
    - Gtk->main()

  * timeout callback
    - start website poll script (as you did)
    - add I/O watcher with Glib::IO->add_watch() on the filehandle

  * io_watch callback
    - check output of poll script (resp. program exit)
      and update tray icon if necessary

This is similar to your threading aproach, just without threads ;)

Regards,

Jörn

-- 
LINUX - Linux Is Not gnU linuX



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