PC Review


Reply
Thread Tools Rate Thread

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

 
 
Brendan Miller
Guest
Posts: n/a
 
      4th Feb 2004
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.
 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      5th Feb 2004
Brendan Miller <(E-Mail Removed)> 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 - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Application.Exit() vs Environmrnt.Exit(0) =?Utf-8?B?VGFvZ2U=?= Microsoft C# .NET 1 19th Apr 2007 03:37 AM
What's the main difference between Application.Exit() and Application.ExitThread()? Stan Microsoft Dot NET Framework Forms 1 30th Apr 2005 02:25 AM
application.exit, application.exitthread exit application problem =?Utf-8?B?TWlrZSBTaWx2ZXI=?= Microsoft Dot NET Framework Forms 2 24th Nov 2004 03:14 AM
RE: How can I safe exit my application when the user terminates the application from the Control panel? Dolphin White Microsoft Dot NET Compact Framework 3 6th Sep 2003 01:12 AM
How can I safe exit my application when the user terminates the application from the Control panel? Dolphin White Microsoft Dot NET Compact Framework 1 4th Sep 2003 03:47 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:29 PM.