I have a program wherein I will check if a file exists. If it does, the form will load. But if not, a messagebox will appear to inform the user, and then the application needs to close without showing the form.
How do I do this properly? I tried using this code on the constructor:
Environment.Exit(-1);
It does what I want, but from what I've read it's not a good way to do it. Is this correct? Or shall I just go with using the above code.
You don't need to call anything if you put your check before the application run of the main form
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// Check for file
if(!File.Exists("your file to check"))
{
MessageBox.Show(.....)
}
else
{
Application.Run(new frmMain());
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With