End program during input validation
Gentlemen,
I have a question that I can't seem to find the answer for through google or me lil VB book here. I am aware that if you want to close a form you have me.close but what if you want a program to terminate? Given situation:
You have failed to give me "Staring Point".
If you don't give me "Staring Point" the program will terminate.
I'd like to terminate the entire program based on dialogresult. Do I just kill my main form or is there a line I can put in there to exit program?
Thanks again for all your help.
Re: End program during input validation
If the code is part of the main form then Me.Close will close that form and exit the application, assuming your shutdown mode is the default "when main form closes". Anywhere else you would need to call Application.Exit.
Re: End program during input validation
Re: End program during input validation
Quote:
Originally Posted by
jmcilhinney
If the code is part of the main form then Me.Close will close that form and exit the application, assuming your shutdown mode is the default "when main form closes". Anywhere else you would need to call Application.Exit.
Why is it that in some situations, "End" doesn't work to close the program while "Application.Exit()" will, and strangle enough I've seen "Application.Exit()" fail but when replaced with "End" the program exits as desired?
I've even experienced cases where End and Application.Exit() fail.. yet Application.ExitThread() succeeds. (Obviously this would only work on the main thread)
I've seen this several times and I'm always puzzled..
Btw, I know Application.Exit() can be overruled by other forms, just look at the documentation of the first overload of Application.Exit(e as System...)
I've never used Environment.Exit(0).. will this always work?
Re: End program during input validation
Quote:
Originally Posted by
Philly0494
Why is it that in some situations, "End" doesn't work to close the program while "Application.Exit()" will, and strangle enough I've seen "Application.Exit()" fail but when replaced with "End" the program exits as desired?
I've even experienced cases where End and Application.Exit() fail.. yet Application.ExitThread() succeeds. (Obviously this would only work on the main thread)
I've seen this several times and I'm always puzzled..
Btw, I know Application.Exit() can be overruled by other forms, just look at the documentation of the first overload of Application.Exit(e as System...)
I've never used Environment.Exit(0).. will this always work?
First up, never, ever use End. End is like terminating your process from the Task Manager. There's never a reason to do that in code.
As for Application.Exit being cancelled by a form, let's keep in mind that this your code we're talking about here. It's your code that would be calling Application.Exit and it's your code that would be cancelling it. If that's not the behaviour you want then why code it in the first place?
Environment.Exit is what you'd call in a Console app, given that the Application class is a member of System.Windows.Forms and only exists in WinForms apps.