views:

196

answers:

3

Hi,

I have an application which when I close the Windows, it exits gracefully and quickly (checked also in Task Manager and Process Explorer - the process isn't there anymore) but the OS doesn't. It seems that OS just ignores the Shutdown.

But if I try to close once more the Windows, now everything is ok. The system shuts down in a very normal way.

  1. Why?
  2. How can I fix this?

Details about my app:

  • multithreaded
  • has a tray icon
  • doesn't do any special processing of WM_QUERYENDSESSION (or similar) OS messages
  • doesn't have any special driver, DLL hook etc.

Any ideas how to fix it?

PS: I'm at your disposition with and further details upon request

+1  A: 

Do you indeed return TRUE to the WM_QUERYENDSESSION (or similar) OS messages? You might get the message, close the app and return FALSE.

GSerg
No, I don't do any processing on that messages. IOW, I don't hook them and hence the default message queue returns 'True'.
Ah. I thought by saying "doesn't do any special processing" you meant not doing odd things in the handler, but just closing the app.
GSerg
@plainth: I think you should trace this. Could be the default message queue doesn't return "true" for all handlers (for whatever reason, hence the need for tracing), but still call just enough of the terminate procs to actually shut down the application.
Paul-Jan
A: 

Dear,

If the application still doing work on the background this could be prevent Windows to shutdown.

You could check if the AutoEndTasks settings are enabled and enabled it if not :

http://technet.microsoft.com/en-us/library/cc978604.aspx

Best Regards

madshiva
No, the application process handle disappears from the list of processes. Also, it doesn't interact with any system service(s). OTOH, I cannot rely on the AutoEndTasks (or on any other external setting) because I don't control the computer(s) on which the app will be deployed.
Dear, Yes ok I think that this parameter was 1 by default but not, it's my mistake, then I think than one of your thread block.If it's a console application you could use the SetConsoleCtrlHandler with CTRL_SHUTDOWN_EVEN to fix it.http://msdn.microsoft.com/en-us/library/ms686016%28VS.85%29.aspxBest Regards
madshiva
+1  A: 

Strange but almost exactly the same problem bugged us this week.

The application ran in the tray, closed but prevented windows from shutting down. So having been there, I'll share what fixed the problem for us.

  • Removing a datamodule fixed the problem.
  • Removing the NMsmtp component fixed the problem.
  • Implementing the suggestion given in this bug report fixed the problem on my workstation, but not on another.

In the end, we choose to just remove the NMsmtp component for wich we didn't have the source code and changed to using Indy.

Most likely, your situation will differ therefore I'd suggest you do like we did and start stripping everything from you project until it works.

Lieven