How to close the application before it is fully downloaded?

Is it possible to completely prevent MainForm from loading during application startup (don’t know how to call it, perhaps component initialization)?

I tried:

public MainForm()
{
    if (true)
    {
        Application.Exit();
        return;
    }
    InitializeComponent();
}

and

public MainForm()
{
    if (true)
    {
        this.Close();
        Application.Exit();
        return;
    }
    InitializeComponent();
}

and without a "return"; also.

The first one does virtually nothing, while the second solution calls "Unable to access the remote object." error?

Is it possible to close the entire application before it is fully downloaded?

Just to make it clear, I want the application to not load in case of a failure in connecting to the database.

+5
source share
3 answers

Try Environment.Exitas described here .

+6
source

ho1, Environment.Exit - . :

public MainForm()
{
    if (true)
    {
        Environment.Exit(0);
    }
    InitializeComponent();
}

, true if-statement.

+9

I think the answer given by rob_g is the way to go. Having a database initialized and confirmed before the form is displayed is the best solution in my opinion! You also remove unnecessary logic from the form constructor, since the form does not have to worry about db initialization.

0
source

All Articles