I am trying to figure out which I should be using. On closing my WinForm app fires of a Form in Dialog mode. That form runs a Background worker that Syncs the DB with the remote DB and displays it's progress on the "Splash Form."
I have a method like so:
private void CloseMyApp()
{
SaveUserSettings();
splashForm = new SplashForm();
splashForm.ShowDialog();
Application.ExitThread();
//Application.Exit();
}
which is what I call to close my app from Menu --> Exit and in the Form_FormClosing()
event. Application.Exit()
gives the following error -->
Collection was modified; enumeration operation may not execute.
Now I read that Environment.Exit()
is brutal and means there is probably something wrong with your app (see here).
Application.ExitThread()
works but I am concered that it may only be APPEARING to work and as I have never used it before I am not sure when it is normally appropriate to do so.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…