-
Jan 31st, 2014, 10:49 AM
#1
Thread Starter
PowerPoster
Preferred way to exit an application?
What is the preferred method to shut down an application? I've always used "End" in the Form_Closing Event. I know this isn't a big deal but still want to stay with the current accepted standard.
Thanks,
-
Jan 31st, 2014, 11:10 AM
#2
Re: Preferred way to exit an application?
close all forms, stop all processes, dispose of any remaining objects, and quietly exit. Make sure that your Application Settings are set correctly (there is an option where you can control if the app ends on the closing of the main form, or when the last remaining form is closed... select according to your needs).
-tg
-
Jan 31st, 2014, 11:48 AM
#3
Thread Starter
PowerPoster
Re: Preferred way to exit an application?
tech,
That doesn't sound like a quiet exit. I know how to close all forms, not sure how to stop "All" processes, not sure how to tell what remaining objects need disposed. Applications Settings I know nothing about. Never used it before. Do you have any code examples or screenshots or links?
-
Jan 31st, 2014, 11:52 AM
#4
Re: Preferred way to exit an application?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 31st, 2014, 11:59 AM
#5
Thread Starter
PowerPoster
Re: Preferred way to exit an application?
That's what I was looking for Paul...thanks!
I'm guessing that statement goes in the Form_Closing() Event?
-
Feb 1st, 2014, 08:09 AM
#6
Re: Preferred way to exit an application?
Originally Posted by blakemckenna
What is the preferred method to shut down an application? I've always used "End" in the Form_Closing Event. I know this isn't a big deal but still want to stay with the current accepted standard.
Thanks,
It's not a big deal? Using END is a big deal and it is not shutting down any thing. It is simply crashing your application.
Classic VB - Why is using the 'End' statement (or VB's "stop" button) a bad idea
-
Apr 7th, 2014, 08:49 PM
#7
Frenzied Member
Re: Preferred way to exit an application?
My application enters in the MyApplication_Startup event in which I call a login screen. If authentication is successful then the application opens its "Startup form". If authentication is not successful then I want to exit the application before the startup form is shown.
In the event of an unsuccessful login:
Firstly, I can't call Application.Exit directly from this event. I can only call it from a sub in another module.
Secondly, if I don't follow it with the End command, the startup form opens.
How can I close the application from this event without using the End command?
-
Apr 7th, 2014, 09:01 PM
#8
Hyperactive Member
Re: Preferred way to exit an application?
If authentication is not successful then I want to exit the application before the startup form is shown.
Might I suggest looking at JMC's codebank submissions. He has a great on on logon forms. Helped me in the past.
-
Apr 7th, 2014, 09:20 PM
#9
Re: Preferred way to exit an application?
Originally Posted by robertx
My application enters in the MyApplication_Startup event in which I call a login screen. If authentication is successful then the application opens its "Startup form". If authentication is not successful then I want to exit the application before the startup form is shown.
In the event of an unsuccessful login:
Firstly, I can't call Application.Exit directly from this event. I can only call it from a sub in another module.
Secondly, if I don't follow it with the End command, the startup form opens.
How can I close the application from this event without using the End command?
Did you actually bother to read the documentation for that event? Why do I even ask? If you had then you would have seen this:
Originally Posted by MSDN
You can use the Cancel property of the e parameter to control the loading of an application's startup form. When the Cancel property is set to True, the startup form does not start.
That's 30 seconds work to find that and reading the documentation should have been the first thing you did.
Originally Posted by detlion1643
Might I suggest looking at JMC's codebank submissions. He has a great on on logon forms. Helped me in the past.
You can follow the CodeBank link in my signature below and check out my WinForms Login thread, which demonstrates cancelling the Startup event.
-
Apr 7th, 2014, 10:33 PM
#10
Frenzied Member
Re: Preferred way to exit an application?
Originally Posted by detlion1643
Might I suggest looking at JMC's codebank submissions. He has a great on on logon forms. Helped me in the past.
Originally Posted by jmcilhinney
You can follow the CodeBank link in my signature below and check out my WinForms Login thread, which demonstrates cancelling the Startup event.
Thanks. Yes the codebank submission was very helpful.
e.Cancel closes the app without the need for End or Application.Exit and also does so more quickly and efficiently.
-
Apr 7th, 2014, 10:35 PM
#11
Re: Preferred way to exit an application?
Originally Posted by robertx
Thanks. Yes the codebank submission was very helpful.
e.Cancel closes the app without the need for End or Application.Exit and also does so more quickly and efficiently.
That Startup event would be raised from the Main method and then the creation of the startup form and the call to Application.Run would be inside an If statement that checks whether e.Cancel is False. It's quicker and more efficient because it stops things being built in the first place rather than tearing them down afterwards.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|