Application.Exit or End

P

Pete Smith

Which is the appropriate one to use in the above choice?
VB.Net. .Net Framework 1.1
Thank you,
Pete
 
C

Chris

Pete said:
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
 
P

Pete Smith

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
 
H

Herfried K. Wagner [MVP]

Pete Smith said:
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'?
 
K

Ken Halter

Pete Smith said:
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.
 
G

Guest

What do you do if you start you application from a sub main and open a form
within sub main?
 
P

Pete Smith

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
..
 
H

Herfried K. Wagner [MVP]

Pete Smith said:
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'.
 
C

Cor Ligthert [MVP]

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
 
C

CMM

<shame> Oops... I had a VB.Classic flashback.... it's Me.Close. Just like H.
Wagner said in another post.
 
?

=?Windows-1252?Q?Jos=E9_Manuel_Ag=FCero?=

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" <[email protected]> escribió en el mensaje | Which is the appropriate one to use in the above choice?
| VB.Net. .Net Framework 1.1
| Thank you,
| Pete
 
P

Pete Smith

Thank you for your thoughts.
-Pete


"José Manuel Agüero" <chema012 en hotmail.com> wrote in message
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" <[email protected]> escribió en el mensaje
| Which is the appropriate one to use in the above choice?
| VB.Net. .Net Framework 1.1
| Thank you,
| Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top