Re: Running Programs Stop by GeneW
GeneW
Fri Mar 03 10:07:28 CST 2006
As a final followup...
Luckily, since all my forms derive from a base class I was able to override
all my forms with OnClosing in one place. I added a static bool that
indicates whether I am processing a Program Running Stop message already so I
don't recursively try to do my shutdown tasks...duh. This totally worked. The
system dialog did NOT come up, but I think that was because the MainForm (the
one used with Application.Run) was not the form that recieved the OnClosing.
Just a guess.
So, cool, thanks again
"GeneW" wrote:
> Thank you all, I think I have found a solution, here is a summary of what I
> think I've learned
>
> 1. In all the forms of your application, override OnClosing and respond by
> setting e.Cancel to true - this prevents immediate termination
>
> 2. If you change the form in response to the OnClosing (for example, if
> Form1 gets the OnClosing, make Form1 invisible, and bring up Form2), this
> appears to give you all the time you need to shutdown.
>
> 3. Do whatever you need to clean up for termination (just like you actually
> had an exit or quit in a normal application).
>
> 4. Exit your application.
>
> The only side effect seems to be that the "not responding" dialog still
> comes up after you terminate, but I can live with that.
>
> In my experiments, recieving the OnClosing in Form1, bringing up Form2
> (actually named the same thing as Form1) waiting 20, 30, 40 seconds
> (simulating shutdown tasks) while Form2 was up before exiting my application
> seemed to work.
>
> It would be nice if you could do something that basically told the system,
> "Yes I'm still alive and no, I do not want to shutdown now" but if the above
> works in my real application I can live without it.
>
> Again, thanks for the help....
>
>
> "Chris Tacke, MVP" wrote:
>
> > I was afraid that might happen. What it likely does (this is how I'd do it
> > anyway) is it first is nice and sends a WM_CLOSE toallow the app to clean up
> > and exit gracefully. If after a period of time you see the Window is still
> > there, you assume it's deadllocked and you use TerminateProcess on it.
> > They're nice and give you a dialog - I don't know of any way to suppress it.
> > So your clean up takes a while? Any way to shorten that?
> >
> > -Chris
> >
> >
> >
> >
> > "GeneW" <GeneW@discussions.microsoft.com> wrote in message
> > news:A7369979-006D-4F7D-A628-4CD745643C44@microsoft.com...
> > > Well this sort of works. It appears that I can override OnClosing and then
> > > set e.Cancel to true to prevent immediate termination. However, the system
> > > brings up a dialog (not responding blah blah blah) -- and now it is a
> > > race,
> > > can I get correctly shutdown before the user hits "End Now".
> > >
> > > So, obviously, this leads to - can I suppress the dialog? Or possibly
> > > "respond" in such a way that the dialog does not appear? Or change the
> > > language of the dialog to ask the user to wait? The language of the dialog
> > > appears to indicate that I can "respond" in some way...
> > >
> > > "<ctacke/>" wrote:
> > >
> > >> I've not checked, but it likely sends a WM_CLOSE to your top level Form.
> > >> An
> > >> IMessageFilter would get that.
> > >>
> > >> -Chris
> > >>
> > >>
> > >> "GeneW" <GeneW@discussions.microsoft.com> wrote in message
> > >> news:AC179F99-7224-4BD5-817C-8748DB90D8F2@microsoft.com...
> > >> > Is there some way to be notified when the user stops my program via
> > >> > Settings->System->Memory->Running Programs->Stop?
> > >> >
> > >> > Currently, my application does not shutdown cleanly when terminated
> > >> > this
> > >> > way
> > >> > (various problems can occur - file not completed, associated background
> > >> > programs not shutdown, etc.)
> > >> >
> > >> >
> > >>
> > >>
> > >>
> >
> >
> >