Override WndProc is stopping shutdown

D

dkisting

Hello,

I am overriding the WndProc in my main form of a Windows application
and the design is for it to ask for some info, kill the application,
and continue on to either shutdown or restart. This is working fine
for the go into hibernation or standby mode, however with shutdown, it
stops after receiving the advice and killing itself. Here is my code:

if (m.Msg == WM_SHUTDOWN)
{
m.Msg = WM_SHUTDOWN;
m.Result = (IntPtr) 1;

KillAgentWithStatusChange(); //this asks for information and than
kills the application

base.WndProc(ref m);

return;

}

The reason I am killing the application is because Windows (for some
reason) won't shut down with the application running. Even after
removing this code, it still does not do the trick. What in the
application could cause Windows not to shutdown when prompted?

Many thanks in advance!

Dan Kisting
 
M

Mehdi

The reason I am killing the application is because Windows (for some
reason) won't shut down with the application running. Even after
removing this code, it still does not do the trick. What in the
application could cause Windows not to shutdown when prompted?

Maybe you should try to find out why is your application preventing Windows
from shutting down properly instead of doing some dirty tricks like
overriding WndProc to kill your app. When windows wants to shut down, it
sends the WM_QUERYSHUTDOWN and the WM_SHUTDOWN messages in sequence to all
running applications. If any application returns FALSE from
WM_QUERYSHUTDOWN, windows aborts the shutting down process. This can happen
when, for example, you are preventing the main form of your application to
close by handling the Closing event and settings e.Cancel to true. In this
case, your application refuses to shutdown preventing windows from shutting
down.
 
H

Herfried K. Wagner [MVP]

The reason I am killing the application is because Windows (for some
reason) won't shut down with the application running. Even after
removing this code, it still does not do the trick. What in the
application could cause Windows not to shutdown when prompted?

Check out 'SystemEvents.SessionEnding'.
 
D

dan kisting

I agree and have looked at that, but it is not a dirty trick, there is
actually logic which needs to prompt a user for a change in status
before they shutdown. Like I said, even after removing all of the
logic in the override, it is still not shutting down. Would any
threading issues have to do with it not shutting down? I am closing
all of my threads (2), but I will look at this.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top