class methods
ofTimer lets you run code periodically with the specified frequency. Use it on a class that extends ofThread.
class Scheduler: public ofThread {
public:
Scheduler() {
timer.setPeriodicEvent(1000000000); // this is 1 second in nanoseconds
startThread();
}
private:
ofTimer timer;
void threadedFunction() {
while(isThreadRunning()) {
timer.waitNext();
// Do your thing here. It will run once per second.
}
}
}
The timer above will wake up at 1 second intervals no matter how long the rest of the task takes. If the last execution took more than 1 second, it'll wake up right away and execute the next. It uses the most accurate timing functions in every OS.
Reset the starting instant of the periodic event to now.
Sets the frequency in \p nanoseconds that events happen.
The timer will begin calculating the events beginning the moment the function is called.
Parameters:
nanoseconds The number of nanoseconds between events.
Sleep this thread until the next periodic event.
Last updated 星期二, 19 十一月 2024 17:25:43 UTC - 2537ee49f6d46d5fe98e408849448314fd1f180e
openFrameworks is developed and maintained by several voluntary contributors.
Donations help support the development of openFrameworks, improve the documentation and pay for third party services needed for the project.
If you are using openFrameworks commercially or would simply like to support openFrameworks development, please consider donating to the project.
If you have any doubt about the usage of this module you can ask in the forum.
If you want to contribute better documentation or start documenting this section you can do so here
If you find anything wrong with this docs you can report any error by opening an issue