Click here to Skip to main content
15,887,861 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
C# newbie!
I need to exit my program as soon as it starts if certain conditions are not met.
I know what the conditions I want to verify but not what event to respond to or how to exit the program.
Thanks In Advance
Posted

I'm assuming this is a WinForms app?

If you can measure those conditions external to you main window, then open up program.cs and test there. Don't launch the form if you're not happy with the environment.

Cheers.
 
Share this answer
 
Application.Exit() should work for you.
 
Share this answer
 
Comments
Dalek Dave 3-Sep-10 11:16am    
It's what I use to get out of Dodge.
C#
static void Main()
{
    // ...
    if (!condition)
        return;
    Application.Run(new Form1());
}
 
Share this answer
 
v2
This is what I did, it looks good so far

C#
static void Main()
        {
            
            if (AllGood)
            {
                MessageBox.Show("Bye);
            }
            else
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
            }
        }
 
Share this answer
 

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