A graceful termination of the application, either in response to some input or by internal logic. Usually applied for applications that need to run certain code in order to terminate in consistent way.
Questions tagged [application-shutdown]
170 questions
38
votes
4 answers
Shutting down a WPF application from App.xaml.cs
I am currently writing a WPF application which does command-line argument handling in App.xaml.cs (which is necessary because the Startup event seems to be the recommended way of getting at those arguments). Based on the arguments I want to exit the…

Joey
- 344,408
- 85
- 689
- 683
28
votes
2 answers
How to log within shutdown hooks with Log4j2?
Log4j2 also uses shutdown hooks to end it's services. But of course I want to log throughout the whole lifecycle of my application - shutdown included. With Log4j this was no problem. Now it seems to be impossible. Logging shuts down, while my…

Martin
- 607
- 1
- 8
- 17
19
votes
3 answers
Windows shutdown hook on java application run from a bat script
I have a bat script which runs a java application. If I press ctrl+c on it, it the application terminates gracefully, invoking all the shutdown hooks. However, if I just close the cmd window of the bat script, the shutdown hooks are never invoked.…

Zoltán
- 21,321
- 14
- 93
- 134
16
votes
1 answer
Using JavaFX Application.stop() method over Shutdownhook
So im using shutdownhook to clean up. But since its not always guaranteed that shutdownhooks thread executes, should i just push this code onto JavaFX Application Thread (method stop()), which executes every time i close my application? Code is not…

Tomas Bisciak
- 2,801
- 5
- 33
- 57
15
votes
6 answers
How to debug a crash that only occurs on application shutdown? (Delphi)
So, after some recent changes we discovered that one of our oldest applications is sometimes crashing on shutdown. This manifests itself either in the form of "Runtime error 216" messages or in a message from Windows Error Reporting that the…

Oliver Giesen
- 9,129
- 6
- 46
- 82
15
votes
3 answers
JUnit4 : Test a shutdown hook is called
I have a method which adds a shutdown hook. I need to test (via JUnit) that the code executed in the hook is called :
public void myMethod(){
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
…

Rémi Doolaeghe
- 2,262
- 3
- 31
- 50
13
votes
1 answer
Is there something like finally() in Go just opposite to what init()?
Is there something in Go which do just opposite to what init() do inside a package?

Prashant
- 3,823
- 3
- 25
- 40
13
votes
3 answers
How to properly shutdown log4j2
If one is not running inside a web application, what is the proper way to shutdown Log4j2? I only see a noop LogManager.shutdown()

user671731
- 489
- 1
- 8
- 17
13
votes
4 answers
Determine exit status within the java shutdown hook thread
I would like to determine the exit status of the process during the shutdown hook runtime.
I want to have a logic which is based on the status code (0 or nonzero)
(ex: if zero do nothing else nonzero send an alert email)
Do you know how I can get…

Kostas
- 702
- 3
- 8
- 17
12
votes
3 answers
How to call event before Environment.Exit()?
I have a console application in C#. If something goes wrong, I call Environment.Exit() to close my application. I need to disconnect from the server and close some files before the application ends.
In Java, I can implement a shutdown hook and…

Makah
- 4,435
- 3
- 47
- 68
11
votes
3 answers
How to fix "Google Chrome did not shutdown properly" in Windows 8.1
When shutting down Windows 8.1, Google Chrome produces the error message "Google Chrome did not shutdown properly". How can I get Chrome to shut down without giving me that error message?
I don't have to be logged in as a Google user.

user3237328
- 111
- 1
- 1
- 4
11
votes
3 answers
C++ graceful shutdown best practices
I'm writing a multi-threaded c++ application for *nix operating systems. What are some best practices for terminating such an application gracefully? My instinct is that I'd want to install a signal handler on SIGINT (SIGTERM?) which stops/joins my…

fredbaba
- 1,466
- 1
- 15
- 26
10
votes
7 answers
How to restart an application completely?
I have an application which starts a Remote Service in its first launched activity. Then, in another activity, the user can set the configuration of the application. Please note that this second activity isn't bound to the Service and I don't wish…

WhiskThimble
- 547
- 3
- 10
- 23
9
votes
3 answers
Express.js app not shutting down cleanly with server.close()
I'm trying to properly close a MongoDB connection when the app is shut down. Here is the code:
var express = require('express')
, http = require('http')
, mongoose = require('mongoose')
, path = require('path');
var app =…

mart1n
- 5,969
- 5
- 46
- 83
8
votes
2 answers
Is there a Delphi event that is guaranteed to be called when an app terminates but before any forms are destroyed?
I am using Delphi 6 Pro. I need an event that will fire when my application is definitely shutting down but before any Forms are destroyed. I thought about trapping WM_QUIT messages in the main form WndProc() but that didn't work because the Forms…

Robert Oschler
- 14,153
- 18
- 94
- 227