Re: [Vala] repeat every n seconds
- From: Abderrahim Kitouni <a kitouni gmail com>
- To: Andrew Higginson <at higginson gmail com>
- Cc: vala-list gnome org
- Subject: Re: [Vala] repeat every n seconds
- Date: Fri, 21 Oct 2011 07:23:56 +0100
في ج، 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]