We help IT Professionals succeed at work.

What is the best way to start and end an application?

264 Views
Last Modified: 2013-11-26
What is the best/recommended way to start and end an application? I am using VB.NET 2008

e.g. In VB 6, I can create a Main sub which will be the startup sub. (Not sure this is the best way either)
Comment
Watch Question

Serge FournierAnalyst Programmer
CERTIFIED EXPERT

Commented:
most visual basic application start with a windows interface (a form)

in wich you add code and objects, like buttons or input windows

when the user close this windows, a sub can be executed "on close" condition to close open files and supress objects (= nothing)

i am sure there is plenty of code example on internet and can't really post an example here, since vs2008 is a complete project with many files

try go look on an open source web site to see examples in vs 2008

Author

Commented:
hi wildboy85,

Is this the best way to start the application?

If I have several forms in my project, which should I set as the startup form? Should I set the 1st form which would appear as the startup form even if it is only a splash screen? What if the startup form will depend on user settings?

In closing the application, what if I have several forms loaded? I want to end the application (close all open forms) when the Main form is closed. Do I have to add code to check which forms are loaded and unload them through code on the OnClose event of the Main form?
Serge FournierAnalyst Programmer
CERTIFIED EXPERT

Commented:
here is some examples for visual studio 2008 projects

http://msdn.microsoft.com/en-us/vcsharp/ms789074.aspx

no you do not have to close all forms on exit, the general setup from vs 2008 will compile your program to do that, as to release all objects and files, i think it does all that too, but a good programmer would close them on exit anyway

and yes there is always an initial form if your program use forms

it would be long to explain all those things here, since a project is complicated in visual studio 2008 (i use vs 2005, but will soon migrate to 2008)

the splash screen is not a form :P ( well maybe yes, but not in my book)

jsut be sure you close the external connections in exit, like a database connection, file connection etc. the kinda of stuff you think that it should not stay open or on the next program run, it might generate an error saying "the connection cannot be open, another application is using it"

normally, all those will be closed on exit, but hey, if visual would be perfect, there would never be any "the connection cannot be open, another application is using it" error...
High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
>>no you do not have to close all forms on exit,
Does that mean you recommend I set the Shutdown mode to "When startup form closes"?

hi Idle_Mind,

Thanks, I believe that is what I need for the startup form.

What about the closing of the application? Is there a "Shutdown" command/method which will close the whole application and trigger the Shutdown event?
Serge FournierAnalyst Programmer
CERTIFIED EXPERT

Commented:
the shutdown command is the red x in right corner of the window :P

it's there by default

when you close the main windows form, it close all childrens window (normally)
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.