Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
Hey

consider this loop:
C#
while(true)
{
...
    if(expr == true)
    {
        //exit program
    }
...
}

I just wana do that "exit program". When I use the close() method the form is closed but the program is still running. Even when I use dispose() is the same thing. I used to do this with exit(0) in c++. Whats the equivalent in c#?
Posted
Updated 1-Dec-10 9:33am
v3

You shouldn't ever assume that calling "exit", or in this case "close" will clean up allocations, abort threads, and release resources. I think I'm one of the few people here that uses destructors, empties collections, unhook delegates, etc before letting the program "close".
 
Share this answer
 
Application.Exit()[^] method can be used as equivalent of exit(0) in C++. However, you must call necessary destructors, empty the collections used and unhook the delegates etc., before doing this.
 
Share this answer
 
I have also been told that:

System.Diagnostics.Process.GetCurrentProcess().Kill();


Can do a decent job of releasing resources and stopping the process, but I'm not sure if it is the best solution to your situation.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900