Closing Applications before shutting down or entering sleep mode