Possible Duplicate:
Application.Exit
I have a Winforms app in which Application.Exit() fails to run.
public Form1()
{
InitializeComponent();
path=parseINI();//Gets path from ini file
}
In my case, Application.Exit() is being called from the parseINI method, where it doesn’t work. Is the problem that its being called when the app is starting? I stuck it in another method that runs after the form is loaded, and it works there. I did use Environment.Exit in my parseINI method, and that worked (despite it being for console apps rather than WinForms).
EDIT: I should probably add that its there as a check, to make sure a file being read is formatted correctly, if it is, then its not called, otherwise the program exits.
This might be because you still haven’t started the application via
Application.Runwhen the Form ctor executes.The common startup code template goes like this:
If that is the case, you call Application.Exit before Application.Run. So after you have called exit, you effectively call Run, and therefore, the application runs.