Questions tagged [application-shutdown]

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.

158 questions
37
votes
3 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
  • 316,376
  • 76
  • 642
  • 652
19
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
  • 413
  • 1
  • 4
  • 14
18
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
  • 19,217
  • 10
  • 81
  • 124
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
  • 8,745
  • 5
  • 43
  • 81
15
votes
1 answer

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,034
  • 3
  • 26
  • 45
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
  • 459
  • 1
  • 7
  • 16
12
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
  • 672
  • 3
  • 8
  • 17
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.
11
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
  • 3,978
  • 3
  • 40
  • 61
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…
9
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
  • 2,863
  • 3
  • 20
  • 36
9
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,326
  • 1
  • 14
  • 24
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,135
  • 5
  • 35
  • 72
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
  • 13,520
  • 17
  • 74
  • 209
7
votes
6 answers

WPF application is not closing correctly

I am calling Application.Current.Shutdown() from a class that is bound to xaml windows with ObjectDataProvider, but the application is not closing. Can anyone help me to understand why? My application is not closing completely after my main window…
Arsen Mkrtchyan
  • 47,086
  • 29
  • 143
  • 178
1
2 3
10 11