Reputation: 868
How can I create a periodic task in Vala? Is there any timer class in Vala that can call a scheduled method at a specified periods? If yes, please provide a sample code.
Update:
this is the sample code based on the answer and comments:
public class Sample : Object
{
private static bool task()
{
stdout.printf("Yay\n");
stdout.flush();
return true; // false terminates timer
}
public static int main(string[] args)
{
Timeout.add_seconds(1, task);
new MainLoop().run();
return 0;
}
}
Upvotes: 4
Views: 578
Reputation: 7153
You can attach a TimeourSource to a main loop. The return value of your callback decides if it gets rerun.
Upvotes: 2