Application.Exit, FormClosing

Zexor

Well-known member
Joined
Nov 28, 2008
Messages
520
Programming Experience
3-5
I remember before that Application.Exit and Application.Restart trigger the FormClosing event. But now it seems it doesn't anymore again? Was there a change somewhere?
 
Both will raise that event, but only with Exit method you can find out if FormClosing was cancelled. It can be used so that you only call Restart if Exit was not cancelled. Both will give CloseReason.ApplicationExitCall by themselves, but if you use Exit first and that is not cancelled, then Restart will not raise the event again.
 
what do you mean by only with Exit method? I tried both application.exit and restart and they just exit the app and FormClosing event was skipped. I switched to using me.close instead for the exit command.
 
what do you mean by only with Exit method?
Application.Exit Method (CancelEventArgs) (System.Windows.Forms) This is the only call of those that expose cancellation information.
I tried both application.exit and restart and they just exit the app and FormClosing event was skipped.
I can't reproduce that problem.
I switched to using me.close instead for the exit command.
All the better if you don't need global exit, or restart.
 
Perhaps you could provide a FULL and CLEAR description of what you're actually trying to achieve here. Either you're doing something wrong or something is broken in your project or your system but we can't know which unless we know what you're actually doing.
 
Back
Top