xtd 0.2.0
Loading...
Searching...
No Matches

◆ restart()

static void xtd::forms::application::restart ( )
static

Shuts down the application and starts a new instance immediately.

Remarks
Applications are restarted in the context in which they were initially run.
If your application was originally supplied command-line options when it first executed, restart will launch the application again with the same options.
Examples
The following code example demonstrates the use of application restart method.
#include <xtd/forms/application>
#include <xtd/forms/button>
#include <xtd/forms/form>
#include <xtd/environment>
using namespace xtd;
using namespace xtd::forms;
auto main() -> int {
auto restart_count = environment::get_environment_variable("application_restart_count").empty() ? 0 : parse<int>(environment::get_environment_variable("application_restart_count"));
auto main_form = form::create(string::format("Restart {} times", restart_count));
auto restart_button = button::create(main_form, "Restart", {10, 10});
restart_button.click += application::restart;
environment::set_environment_variable("application_restart_count", int32_object {restart_count + 1}.to_string());
}
bool empty() const noexcept
Checks if the string has no characters, i.e. whether begin() == end().
Definition basic_string.h:804
Represents a boxed integer object.
Definition box_integer.h:52
xtd::string to_string() const noexcept override
Returns a xtd::string that represents the current object.
Definition box.h:109
static void set_environment_variable(const xtd::string &variable, const xtd::string &value)
Creates, modifies, or deletes an environment variable stored in the current process.
static xtd::string get_environment_variable(const xtd::string &variable)
Retrieves the value of an environment variable from the current process.
static std::optional< form_ref > main_form()
Gets the optional main form owned by the application.
static void run()
Begins running a standard application message loop on the current thread, without a form.
static void restart()
Shuts down the application and starts a new instance immediately.
static button create()
A factory to create an xtd::forms::button.
event< control, event_handler > click
Occurs when the xtd::forms::control is clicked.
Definition control.h:1482
static form create()
A factory to create an xtd::forms::form.
static basic_string format(const basic_string< char > &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
int parse< int >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition parse.h:137
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition xtd_about_box.h:12
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10