xtd 0.2.0
Loading...
Searching...
No Matches
environment_program_exit.cpp

Shows how to use xtd::environment::program_stopped event.

#include <xtd/xtd>
namespace environment_program_exit_example {
class program static_ {
public:
// The main entry point for the application.
static auto main(const argument_collection& args) {
environment::program_exit += delegate_(auto e) {
console::write_line("The program is stopped {}ly!", e.exit_mode());
};
console::write_line("Start");
// Do something...
auto do_something_thread = thread{[] {
for (auto step = 0; step < 50; ++step) {
console::write('.');
threading::thread::sleep(100_ms);
}
console::write_line();
}};
do_something_thread.start();
do_something_thread.join();
console::write_line("End");
if (args.size() == 1 && args[0] == "exit") {
console::write_line("Before environment::exit");
environment::exit(exit_status::success);
console::write_line("After environment::exit");
} else if (args.size() == 1 && args[0] == "quick_exit") {
console::write_line("Before environment::quick_exit");
environment::quick_exit(exit_status::success);
console::write_line("After environment::quick_exit");
}
}
};
}
startup_(environment_program_exit_example::program::main);
// This code produces the following output :
//
// Start
// ..................................................
// End
// The program is stopped!
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition static.hpp:37
#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
#define delegate_
The declaration of a delegate type is similar to a method signature. It has a return value and any nu...
Definition delegate.hpp:900