C
Chuck
Hello everybody,
I need to abort execution during start up, while the constructor called by
Application.Run is executing.
If the database fails to connect during my application's startup I want to
display a message (no problem here) and then abort the program. However,
after the attached code executes I end up with my main form and a wait
cursor! If I click on the X the form closes. Boss doesn't think an
unhandled exception will impress our customers Can't say that I
disagree.
Anybody have any ideas what I am doing wrong? (Besides, programming for a
living).
public MainFrame() //MDI appication
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
try
{
Initilize(); //attempts to connect to remote database. throws if it
can't.
}
catch(System.Net.WebException we) // this is thrown when the remote
database can't be found.
{
string message = we.Message; //message explaining that database can't
be found. (my text);
message += "\nNotify System Administrator.\nClosing application";
//some add-on text.
MessageBox.Show(message,"Database
Error!",MessageBoxButtons.OK,MessageBoxIcon.Error);
connectFailed = true; //needed to prevent OnLoad event handler from
doing its thing. Form loads even though I have called Exit!
Application.ExitThread(); //This doesn't seem to work. Neither does
Application.Exit() or this.Close();
}
catch(Exception e)
{
throw e; // just a place to put a break point for debugging.
}
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles(); // I am running XP pro.
//Get the running instance.
Process instance = RunningInstance(); //checks for a running instance
of the application. Uses win32 API
if (instance == null)
{
//There isn't another instance, show our form.
SplashScreen.ShowSplashScreen(); // runs on separate thread.
Application.DoEvents();
Application.Run(new MainFrame());
}
else
{
//There is another instance of this process.
HandleRunningInstance(instance);
}
}
I need to abort execution during start up, while the constructor called by
Application.Run is executing.
If the database fails to connect during my application's startup I want to
display a message (no problem here) and then abort the program. However,
after the attached code executes I end up with my main form and a wait
cursor! If I click on the X the form closes. Boss doesn't think an
unhandled exception will impress our customers Can't say that I
disagree.
Anybody have any ideas what I am doing wrong? (Besides, programming for a
living).
public MainFrame() //MDI appication
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
try
{
Initilize(); //attempts to connect to remote database. throws if it
can't.
}
catch(System.Net.WebException we) // this is thrown when the remote
database can't be found.
{
string message = we.Message; //message explaining that database can't
be found. (my text);
message += "\nNotify System Administrator.\nClosing application";
//some add-on text.
MessageBox.Show(message,"Database
Error!",MessageBoxButtons.OK,MessageBoxIcon.Error);
connectFailed = true; //needed to prevent OnLoad event handler from
doing its thing. Form loads even though I have called Exit!
Application.ExitThread(); //This doesn't seem to work. Neither does
Application.Exit() or this.Close();
}
catch(Exception e)
{
throw e; // just a place to put a break point for debugging.
}
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles(); // I am running XP pro.
//Get the running instance.
Process instance = RunningInstance(); //checks for a running instance
of the application. Uses win32 API
if (instance == null)
{
//There isn't another instance, show our form.
SplashScreen.ShowSplashScreen(); // runs on separate thread.
Application.DoEvents();
Application.Run(new MainFrame());
}
else
{
//There is another instance of this process.
HandleRunningInstance(instance);
}
}