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

Re: Override WndProc is stopping shutdown by Mehdi

Mehdi
Tue Mar 14 08:48:56 CST 2006

On 14 Mar 2006 06:25:30 -0800, dkisting@dankisting.com wrote:

> 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.

Re: Override WndProc is stopping shutdown by Herfried

Herfried
Tue Mar 14 12:18:45 CST 2006

<dkisting@dankisting.com> schrieb:
> 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'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Re: Override WndProc is stopping shutdown by dan

dan
Wed Mar 15 07:56:47 CST 2006

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.