xtd 0.2.0
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 argument_collection& args) {
console::write_line("The program is stopped {}ly!", e.exit_mode());
};
// Do something...
auto do_something_thread = thread{[] {
for (auto step = 0; step < 50; ++step) {
}
}};
do_something_thread.start();
do_something_thread.join();
if (args.size() == 1 && args[0] == "exit") {
console::write_line("Before environment::exit");
console::write_line("After environment::exit");
} else if (args.size() == 1 && args[0] == "quick_exit") {
console::write_line("Before environment::quick_exit");
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!
virtual size_type size() const noexcept
Returns the number of elements in the container, i.e. std::distance(xtd::array::begin(),...
Definition basic_array.hpp:246
static void write(arg_t &&value)
Writes the text representation of the specified value to the standard output stream.
Definition console.hpp:462
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
static event< environment, program_exit_event_handler > program_exit
Occurs when the terminates normally (via xtd::environment::exit or returning from the main function).
Definition environment.hpp:535
static void exit()
Terminates this process and returns an exit code to the operating system.
static void quick_exit() noexcept
Terminates this process and returns an exit code to the operating system without completely cleaning ...
Creates and controls a thread, sets its priority, and gets its status.
Definition thread.hpp:45
static void sleep(int32 milliseconds_timeout)
Suspends the current thread for a specified time.
void start()
Causes the operating system to change the state of the current instance to xtd::threading::thread_sta...
#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
xtd::array< xtd::string > argument_collection
Represents the collection of arguments passed to the main entry point method.
Definition argument_collection.hpp:19
@ success
Successful execution of a program. Is equal to EXIT_SUCCESS.
Definition exit_status.hpp:20
@ e
The E key.
Definition console_key.hpp:96
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