views:

18

answers:

1

So I can't seem to completely exit the application, I want this to happen when the user clicks the (x) button. is there a certain command like application.exit I can put somewhere (maybe FormClosed()?)

Thank you!

+2  A: 

After closing the last form, the application should exit on its own.

If it isn't, you probably have some other code which is still running.
Pause the program in a debugger and cehck what it's doing.

SLaks
well i do notice I am overriding the dispose method... is there anywhere I can bypass this?
Spooks
@Spooks: What on earth are you saying?
SLaks
@SLaks, I override most of my diposed methods in MDIChild forms, causing the next MDIChild to popup. It seems that closing the mdiParent happens first, and then calls MDIChild, which trys to open up the next form... so it never actually closes, make sense?
Spooks
@Spooks: You should not be doing that in `Dispose`. Instead, do it in the code that closes the previous form, or maybe in the child's `FormClosing` event (after check the reason).
SLaks
@SLaks so it seems, clients wanted to close the form and move to the next one(thats how the old application worked), there isn't something like application.restart (as it works right away) but instead of restarting, exiting?
Spooks
There is an `Application.Exit()` method, which will probably work.
SLaks
that calls the diposed of the child form :(
Spooks
However, showing forms in the `Dispose` method is a _bad_ idea. You should at least switch to `FormClosed`.
SLaks
As a workaround, you could set a `static` boolean flag before exiting, and check the flag before showing the form.
SLaks
Perfect worked like a charm, thanks! - and I will switch it to FormClosed, seems a lot better
Spooks