Is it possible to prevent MainForm from loading fully during the process of starting up an application (not sure how its called, Component Initialization maybe)?
I've tried:
public MainForm()
{
if (true)
{
Application.Exit();
return;
}
InitializeComponent();
}
and
public MainForm()
{
if (true)
{
this.Close();
Application.Exit();
return;
}
InitializeComponent();
}
and without "return;" as well.
The first one does actually nothing, while the second solution throws up an "Cannot access a disposed object." error?
Is it even possible to close whole Application before its fully loaded?
Just to make it clear I want to prevent application from loading in case of database connection issue.
As ho1 said, Environment.Exit
is the answer. For example:
public MainForm()
{
if (true)
{
Environment.Exit(0);
}
InitializeComponent();
}
That will cause the application to close if the condition is true
in the if-statement.
Try Environment.Exit
as described here.
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