How to properly close a Java application with C # one

I have a Java application that exits correctly when using CTRL-C , the java application saves all the data before disconnecting. Now I am trying to close this java application from my C # console application using Process.Close() , but the application does not save any data when I use it, I also tried Process.CloseMainWindow() , but nothing happens, but also Process.Kill() , but using this process, just killed, without any effort.

How can I raise a hookdown on a java application from a C # console application?

+1
source share
1 answer

The disconnect key cannot be raised by another application.

The shutdown hook is executed when:

  • The program exists normally. For example, System.exit() is called, or the last non-daemon thread exits.
  • The virtual machine is shutting down. e.g. CTRL-C. This corresponds to kill -SIGTERM pid or kill -15 pid for Unix systems.

The shutdown key does not start when:

  • Virtual machine cancels
  • The SIGKILL signal is sent to the virtual machine process on the Unix system. e.g. kill -SIGKILL pid or kill -9 pid
  • A TerminateProcess call is sent to a process on Windows systems.
+2
source

Source: https://habr.com/ru/post/923732/


All Articles