472,125 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,125 software developers and data experts.

Application.exit() vs Environment.exit(-1) vs Application.exitthread()

I am trying to close my application using Application.exit() in the
frmMain_Closing event. When the form closes the process does not. My
application only has one form (no other classes either). The form has
a really long loop which generates approx. 700 .csv files. I do not create
any threads myself (Application.exitthread() doesn't work either).
To counteract this I have decided to use the Environment.exit(-1)
method instead.

What is the difference between the three methods?

Using environment.exit() seems a strange way to do things considering there
is a Application.exit method which claims to do what the Environment.exit()
method does.
Nov 15 '05 #1
1 17299
Brendan Miller <ho**********@hotmail.com> wrote:
I am trying to close my application using Application.exit() in the
frmMain_Closing event. When the form closes the process does not. My
application only has one form (no other classes either). The form has
a really long loop which generates approx. 700 .csv files. I do not create
any threads myself (Application.exitthread() doesn't work either).
Well that's the first problem - you *should* me creating a separate
thread to do your main processing. You should test a flag in that
thread every so often to see whether or not you should exit, and set
that flag in your closing event.
To counteract this I have decided to use the Environment.exit(-1)
method instead.

What is the difference between the three methods?
Application.Exit is to do with message pumps - it effectively means
that Application.Run(...) will return at that point.

Application.ExitThread is similar to Application.Exit, but only for the
message pump on the current thread.
Using environment.exit() seems a strange way to do things considering there
is a Application.exit method which claims to do what the Environment.exit()
method does.


No it doesn't. How is:

<quote>
This method stops all running message loops on all threads and closes
all windows of the application. This method does not force the
application to exit.
</quote>

the same as

<quote>
Terminates this process and gives the underlying operating system the
specified exit code.
</quote>

? Where is the claim you were talking about?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by ZoombyWoof | last post: by
4 posts views Thread by Chuck | last post: by
2 posts views Thread by Dan Keeley | last post: by
4 posts views Thread by Bob Day | last post: by
4 posts views Thread by vul | last post: by
4 posts views Thread by JIM.H. | last post: by
1 post views Thread by =?Utf-8?B?VGFvZ2U=?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.