#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);
auto now = date_time::now();
console::write_line("{:t}.{:D3} Checking status {,2}.",
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};
auto now = date_time::now();
console::write_line("{:t}.{:D3} Creating timer.\n",
now, now.millisecond());
auto state_timer =
timer {{status_checker, &timer_example::status_checker::check_status},
auto_event, 1000, 250};
auto_event.wait_one();
console::write_line("\nChanging period to .5 seconds.\n");
auto_event.wait_one();
state_timer.close();
console::write_line("\nDestroying timer.");
}
};
}
Represents a thread synchronization event that, when signaled, resets automatically after releasing a...
Definition auto_reset_event.hpp:36
Provides a mechanism for executing a method on a thread pool thread at specified intervals....
Definition timer.hpp:49
void change(int32 due_time, int32 period)
changes the start time and the interval between method invocations for a timer, using 32-bit signed i...
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.hpp:175
The xtd::threading namespace provides classes and interfaces that enable multithreaded programming....
Definition abandoned_mutex_exception.hpp:11
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10