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

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

#include <xtd/threading/thread>
#include <xtd/console>
#include <xtd/environment>
#include <xtd/startup>
using namespace xtd;
using namespace xtd::threading;
namespace environment_program_exit_example {
class program static_ {
public:
// The main entry point for the application.
static auto main(const std::vector<ustring>& args) {
environment::program_exit += [](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!
Creates and controls a thread, sets its priority, and gets its status.
Definition thread.h:41
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition static.h: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.h:166
The xtd::threading namespace provides classes and interfaces that enable multithreaded programming....
Definition abandoned_mutex_exception.h:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10