#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) {
now, now.millisecond(),
++invoke_count);
if (invoke_count == max_count) {
invoke_count = 0;
auto_event.set();
}
}
};
class program {
public:
static void main() {
auto auto_event = auto_reset_event {false};
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();
state_timer.change(0, 500);
console::write_line("\nChanging period to .5 seconds.\n");
auto_event.wait_one();
state_timer.close();
console::write_line("\nDestroying timer.");
}
};
}
startup_(timer_example::program::main);
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
static date_time now() noexcept
Gets a xtd::date_time object that is set to the current date and time on this computer,...
#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:168
type_t as(any_object &o)
Casts a type into another type.
Definition __as_any_object.hpp:59
The xtd::threading namespace provides classes and interfaces that enable multithreaded programming....
Definition abandoned_mutex_exception.hpp:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4