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

◆ kill()

void xtd::diagnostics::process::kill ( )

Immediately stops the associated process.

Exceptions
xtd::invalid_operation_exceptionThere is no process associated with this xtd::diagnostics::process object.
Remarks
The xtd::diagnostics::process::kill method forces a termination of the process, while xtd::diagnostics::process::close_main_window only requests a termination. When a process with a graphical interface is executing, its message loop is in a wait state. The message loop executes every time a Windows message is sent to the process by the operating system. Calling xtd::diagnostics::process::close_main_window sends a request to close the main window, which, in a well-formed application, closes child windows and revokes all running message loops for the application. The request to exit the process by calling xtd::diagnostics::process::close_main_window does not force the application to quit. The application can ask for user verification before quitting, or it can refuse to quit. To force the application to quit, use the xtd::diagnostics::process::kill method.
The behavior of xtd::diagnostics::process::xtd::diagnostics::process::close_main_window is identical to that of a user closing an application's main window using the system menu. Therefore, the request to exit the process by closing the main window does not force the application to quit immediately.
Note
The xtd::diagnostics::process::kill method executes asynchronously. After calling the xtd::diagnostics::process::kill method, call the xtd::diagnostics::process::xtd::diagnostics::process::wait_for_exit method to wait for the process to exit, or check the xtd::diagnostics::process::has_exited property to determine if the process has exited.
The xtd::diagnostics::process::wait_for_exit method and the xtd::diagnostics::process::has_exited property do not reflect the status of descendant processes. When xtd::diagnostics::process::kill(entireProcessTree: true) is used, xtd::diagnostics::process::wait_for_exit and xtd::diagnostics::process::has_exited will indicate that exiting has completed after the given process exits, even if all descendants have not yet exited.
Remarks
Data edited by the process or resources allocated to the process can be lost if you call xtd::diagnostics::process::kill. xtd::diagnostics::process::kill causes an abnormal process termination and should be used only when necessary. xtd::diagnostics::process::close_main_window enables an orderly termination of the process and closes all windows, so it is preferable for applications with an interface. If xtd::diagnostics::process::close_main_window fails, you can use xtd::diagnostics::process::kill to terminate the process. xtd::diagnostics::process::kill is the only way to terminate processes that do not have graphical interfaces.
You can call xtd::diagnostics::process::kill and xtd::diagnostics::process::close_main_window only for processes that are running on the local computer. You cannot cause processes on remote computers to exit. You can only view information for processes running on remote computers.