Link to home
Start Free TrialLog in
Avatar of Thomasian
ThomasianFlag for Philippines

asked on

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

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)
Avatar of Serge Fournier
Serge Fournier
Flag of Canada image

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
Avatar of Thomasian

ASKER

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?
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...
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>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?
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)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial