Shows how to use xtd::threading::timer class.
#include <xtd/threading/auto_reset_event>
#include <xtd/threading/timer>
#include <xtd/console>
#include <xtd/date_time>
#include <xtd/startup>
namespace timer_example {
class status_checker {
private:
int invoke_count = 0;
int max_count = 0;
public:
status_checker(int count) {
invoke_count = 0;
max_count = count;
}
void check_status(
std::any state_info) {
auto auto_event = as<auto_reset_event>(state_info);
now, now.millisecond(),
++invoke_count);
if (invoke_count == max_count) {
invoke_count = 0;
auto_event.set();
}
}
};
class program {
public:
static void main() {
auto status_checker = timer_example::status_checker {10};
now, now.millisecond());
auto state_timer =
timer {{status_checker, &timer_example::status_checker::check_status},
auto_event, 1000, 250};
auto_event.wait_one();
auto_event.wait_one();
state_timer.close();
}
};
}