في ج، 21-10-2011 عند 07:16 +0100 ، كتب Andrew Higginson:
> On 21/10/11 01:30, "Luis L. Rodríguez Oro" wrote:
> > Hello friends,
> > 
> > I need run a function indefinitely every N secods, something like this.
> > 
> > using GLib;
> > int seconds = 5;
> > 
> > bool myfunction(){
> >      stdout.printf ("ok\n");
> > 
> >      return true;
> > }
> > 
> > 
> > void main () {
> >      //how run my function every 5 seconds
> >      myfunction(); // this run only one time
> > }
> 
> Use GLib.Timeout.add(), it will run a method every n milliseconds until
> that method returns false. For this to work, you must also run a
> MainLoop to keep the program alive (however you may already have a main
> loop if this is part of a Gtk application or something)
> 
> For example:
> 
> int seconds = 5;
> 
> bool myfunction(){
>     stdout.printf ("ok\n");
>     return true;
> }
> 
> 
> void main () {
>     Timeout.add(seconds * 1000, myfunction);

If you only need to run it every n seconds, it's better to use
Timeout.add_seconds instead.

HTH,
Abderrahim

_______________________________________________
vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to