Java shutdown hook

The JVM can shutdown in either an orderly or abrupt manner. A shutdown hook runs for an orderly shutdown: when the last normal thread terminates, someone calls System.exit or by other platform specific means (such as typing Ctrl-C). Shutdown hooks will not run for an abrupt shutdown of the JVM. As you are pressing the … Read more

Shutting down a computer

Create your own function to execute an OS command through the command line? For the sake of an example. But know where and why you’d want to use this as others note. public static void main(String arg[]) throws IOException{ Runtime runtime = Runtime.getRuntime(); Process proc = runtime.exec(“shutdown -s -t 0”); System.exit(0); }

How do I exit a WPF application programmatically?

To exit your application you can call System.Windows.Application.Current.Shutdown(); As described in the documentation to the Application.Shutdown method you can also modify the shutdown behavior of your application by specifying a ShutdownMode: Shutdown is implicitly called by Windows Presentation Foundation (WPF) in the following situations: When ShutdownMode is set to OnLastWindowClose. When the ShutdownMode is set … Read more

How to properly shutdown java ExecutorService

Recommended way from Oracle API documentation page of ExecutorService: void shutdownAndAwaitTermination(ExecutorService pool) { pool.shutdown(); // Disable new tasks from being submitted try { // Wait a while for existing tasks to terminate if (!pool.awaitTermination(60, TimeUnit.SECONDS)) { pool.shutdownNow(); // Cancel currently executing tasks // Wait a while for tasks to respond to being cancelled if (!pool.awaitTermination(60, … Read more

How to shut down the computer from C#

Works starting with windows XP, not available in win 2000 or lower: This is the quickest way to do it: Process.Start(“shutdown”,”/s /t 0″); Otherwise use P/Invoke or WMI like others have said. Edit: how to avoid creating a window var psi = new ProcessStartInfo(“shutdown”,”/s /t 0″); psi.CreateNoWindow = true; psi.UseShellExecute = false; Process.Start(psi);

Programmatically switching off Android phone

As CommonsWare already said that this is not possible in an Ordinary SDK Application. You need to sign your app with the System Firmware Key. But it’s possible for your app with Root privileges. Try using the following code (if you have SU access): Shutdown: try { Process proc = Runtime.getRuntime() .exec(new String[]{ “su”, “-c”, … Read more