When starting the Windows Forms application, I read the XML file. If this file does not exist or does not have a specific parameter, I want to show the MessageBox to the user pointing to the problem, and then close the application.
I tried to do this in a Loadmain form event using Application.Exit()as follows:
private void MainForm_Load(object sender, EventArgs e)
{
if (!StartupSettingsCorrect())
{
MessageBox.Show("Blabla... Can't start application.");
Application.Exit();
}
}
But it does not seem clean. (The application works, but is "invisible" without a form on the screen.)
What is the best way and place for a clean shutdown in this situation?
Thank you for your help!
source
share