469,958 Members | 1,914 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,958 developers. It's quick & easy.

Application.Exit or End

Which is the appropriate one to use in the above choice?
VB.Net. .Net Framework 1.1
Thank you,
Pete
Jan 30 '06 #1
12 2464
Pete Smith wrote:
Which is the appropriate one to use in the above choice?
VB.Net. .Net Framework 1.1
Thank you,
Pete


As far as I know both should be avoided unless you have a specific
reason to use it. In most cases closing the forms will exit the
program. Why are you trying to use either?

chris
Jan 30 '06 #2
My understating is by calling the above statements will close the
application properly. Like releasing all the resources.... etc.

That is the reason why I am calling the above statements.

Pete
"Chris" <no@spam.com> wrote in message
news:eL**************@TK2MSFTNGP09.phx.gbl...
Pete Smith wrote:
Which is the appropriate one to use in the above choice?
VB.Net. .Net Framework 1.1
Thank you,
Pete


As far as I know both should be avoided unless you have a specific
reason to use it. In most cases closing the forms will exit the
program. Why are you trying to use either?

chris

Jan 30 '06 #3
"Pete Smith" <Pe*********@hotmail.com> schrieb:
My understating is by calling the above statements will close the
application properly. Like releasing all the resources.... etc.

That is the reason why I am calling the above statements.


Both will release resources, but custom cleanup code may not be executed!
Could you describe the design of your application in more detail and where
you are calling 'End'/'Application.Exit'?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jan 30 '06 #4
"Pete Smith" <Pe*********@hotmail.com> wrote in message
news:ur*************@TK2MSFTNGP14.phx.gbl...
My understating is by calling the above statements will close the
application properly. Like releasing all the resources.... etc.

That is the reason why I am calling the above statements.

Pete


If the .Net version of 'End' works anything like the VB6 version, use
anything else. In VB6, sure, it stops the app but in a way that's similar to
shutting your car off while driving. iow, it "yanks the plug" on the app,
possibly leaving automation objects hanging around waiting for task manager
intervention.

--
Ken Halter - MS-MVP-VB (visiting from VB6 world) - http://www.vbsight.com
Please keep all discussions in the groups..
Jan 30 '06 #5
What do you do if you start you application from a sub main and open a form
within sub main?
--
Dennis in Houston
"Chris" wrote:
Pete Smith wrote:
Which is the appropriate one to use in the above choice?
VB.Net. .Net Framework 1.1
Thank you,
Pete


As far as I know both should be avoided unless you have a specific
reason to use it. In most cases closing the forms will exit the
program. Why are you trying to use either?

chris

Jan 31 '06 #6
Application is basically gets the data from the database and prints in a
particualr format. When the user clicks the "Exit" button or "X" on the
right top of the windows form, the application will close.
Thank you,
Pete
..

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:Op*************@TK2MSFTNGP09.phx.gbl...
"Pete Smith" <Pe*********@hotmail.com> schrieb:
My understating is by calling the above statements will close the
application properly. Like releasing all the resources.... etc.

That is the reason why I am calling the above statements.


Both will release resources, but custom cleanup code may not be executed!
Could you describe the design of your application in more detail and where
you are calling 'End'/'Application.Exit'?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jan 31 '06 #7
CMM
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:EB**********************************@microsof t.com...
What do you do if you start you application from a sub main and open a
form
within sub main?


You close the form (Unload Me).
Jan 31 '06 #8
"Pete Smith" <Pe*********@hotmail.com> schrieb:
Application is basically gets the data from the database and prints in a
particualr format. When the user clicks the "Exit" button or "X" on the
right top of the windows form, the application will close.


Simply call 'Me.Close()' inside the form instead of calling 'End' or
'Application.Exit'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jan 31 '06 #9
Pete,

In C# (and other languages) is used a Shared Sub Main as starting point of a
program

In VB Net as in VB6 you have the choise between using that Sub Main or using
the inbuild one in your main-form. (Herfried uses forever that Sub Main in
his samples, I use forever that MainForm (form1).

You would never use End for the reason as Ken Halter has explained.

With a Sub Main you would use
application.exit

With a mainform you would use
me.close

I hope this helps,

Cor
Jan 31 '06 #10
CMM
<shame> Oops... I had a VB.Classic flashback.... it's Me.Close. Just like H.
Wagner said in another post.
"CMM" <cm*@nospam.com> wrote in message
news:Oz****************@TK2MSFTNGP14.phx.gbl...
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:EB**********************************@microsof t.com...
What do you do if you start you application from a sub main and open a
form
within sub main?


You close the form (Unload Me).

Jan 31 '06 #11
Hello group,

Let me give my opinion about how to properly close a Windows Forms application:

If you haven't a Sub Main, that is, your starting object inherits from System.Windows.Forms.Form, you should finish by closing the main form. You can use Application.Exit (or ThreadExit) or even Environment.Exit, but it won't fire events like Closing or Close.

If you have a Sub Main, you can use Application.Run to start one or more consecutive message pumps. You can do it in two ways:
· Using Application.Run(): You have to quit from the message pump by executing Application.Exit (or ThreadExit if you use multiple threads). The inconvenient has been noted above.
· Using Application.Run(ApplicationContext) or Application.Run(Form): This way you work just like when you have one main form: closing the form will finish the message pump. Additionally, if you use an ApplicationContext you can change the ApplicationContext.MainForm at any time, efectively changing your application's main form (the form that will end the message pump when closed). You can still use Application.Exit or ThreadExit to quit without invoking further events.

Regards.
"Pete Smith" <Pe*********@hotmail.com> escribió en el mensaje news:um*************@TK2MSFTNGP12.phx.gbl...
| Which is the appropriate one to use in the above choice?
| VB.Net. .Net Framework 1.1
| Thank you,
| Pete

Feb 1 '06 #12
Thank you for your thoughts.
-Pete
"José Manuel Agüero" <chema012 en hotmail.com> wrote in message
news:OJ**************@TK2MSFTNGP14.phx.gbl...
Hello group,

Let me give my opinion about how to properly close a Windows Forms
application:

If you haven't a Sub Main, that is, your starting object inherits from
System.Windows.Forms.Form, you should finish by closing the main form. You
can use Application.Exit (or ThreadExit) or even Environment.Exit, but it
won't fire events like Closing or Close.

If you have a Sub Main, you can use Application.Run to start one or more
consecutive message pumps. You can do it in two ways:
· Using Application.Run(): You have to quit from the message pump by
executing Application.Exit (or ThreadExit if you use multiple threads). The
inconvenient has been noted above.
· Using Application.Run(ApplicationContext) or Application.Run(Form): This
way you work just like when you have one main form: closing the form will
finish the message pump. Additionally, if you use an ApplicationContext you
can change the ApplicationContext.MainForm at any time, efectively changing
your application's main form (the form that will end the message pump when
closed). You can still use Application.Exit or ThreadExit to quit without
invoking further events.

Regards.
"Pete Smith" <Pe*********@hotmail.com> escribió en el mensaje
news:um*************@TK2MSFTNGP12.phx.gbl...
| Which is the appropriate one to use in the above choice?
| VB.Net. .Net Framework 1.1
| Thank you,
| Pete
Feb 2 '06 #13

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Guinness Mann | last post: by
3 posts views Thread by John Wildes | last post: by
4 posts views Thread by Bob Day | last post: by
3 posts views Thread by Marcel Saucier | last post: by
7 posts views Thread by Jay | last post: by
1 post views Thread by =?Utf-8?B?VGFvZ2U=?= | last post: by
reply views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.