tags:

views:

100

answers:

1

I have a PocketPC C# application written in Visual Studio 2005. It uses nested forms (the user is presented with a form with multiple buttons, when the user selects one a new form is opened).

I've added code so that the 1st form sets it's title to string.Empty to hide it from the Running Programs List. When the 2nd form is showing and the user uses the task manager to stop my app, the 2nd form gets the on close event.

Is there any way of knowing that the close event has come from the task manager so that I can close my application? At the moment when breakpointing the close event, I'm seeing the DialogResult being set as DialogResult.OK (Which isn't helpful) and the 2nd dialog is closed returning control to caller which thinks the user selected OK and opens the next dialog.

I've Googled for info but all the helpful code such as ClosingEventArgs aren't available in the compact framework. Any ideas?

+2  A: 

I may be missing something but if your problem is distinguishing between the 2nd dialog being closed normally, and being closed using task manager, can you not set some kind of marker when the normal close action occurs, before closing? Logically then any close event where the marker has not been set will be down to the task manager?

Colin Pickard
It's something I can look at. I was hoping for a neater solution: I have ~50 dialogs with multiple ways of exiting (The user can hit back to get to the parent form, select buttons opening new forms etc). I'll look at your suggestion though - at the moment it looks like the only way of handling the task manager close. Cheers.
JLWarlow
OK, so I've created a new `ShowDialog()` and new `DialogResult` in my base frame class. The DialogResult.Set sets a flag to say my code set it. Anything from the task manager doesn't hit my new DialogResult.The new ShowDialog calls the base ShowDialog and on return checks the flag to see who closed the dialog. If it wasn't me a static exit app flag is set and I then call Application.Exit, all other ShowDialog's then check this static flag to see if I need to exit. So far so good and the plus is I don't have to change the other 50 dialogs as they already derive from my base frame class!
JLWarlow
I'd +1 for your help, but I need 15 rep 1st! :-(
JLWarlow
That's great, glad you solved it :)
Colin Pickard