Thanks for your help Dave.
Do you mean I should put the validation in main()? If so, is between Application.Set and
Application.Run a sensible place (see below)?
static void Main(){
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
//validation logic
...
Application.Run(new FormMain());
}
"If it's the main form of your application then you won't even need to call Application.Exit - just
let the thread exit on its own."
It is the main form of my application. I'm not sure what you mean by "just let the thread exit on
its own". Do you mean I should use something like:
static void Main(){
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
//validation logic
...
if(validatesOk) Application.Run(new FormMain());
}
"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:O6**************@TK2MSFTNGP05.phx.gbl...
Hi,
You shouldn't be performing the validation logic and throwing an exception
in the constructor of your Form unless you're simply validating arguments.
Do all of the appropriate argument and non-argument validation before
constructing an instance of the Form in the calling code, and decide then
whether you even need to construct the Form in the first place. If it's the
main form of your application then you won't even need to call
Application.Exit - just let the thread exit on its own.
--
Dave Sexton
http://davesexton.com/blog http://www.codeplex.com/DocProject (Sandcastle in VS IDE)
"Jay" <-wrote in message news:uZ**************@TK2MSFTNGP03.phx.gbl...
Thanks for your replies everyone. I'll set a variable as Ben suggested.
Now I have another problem. Application.Exit() appear to do nothing when
it's called anywhere in the
main form's constructor - FormMain(). The programme contines to run as if
it wasn't called, and
stepping through with the debugger shows that it does nothing too. It
appears to work anywere else,
however. Do you have any suggestions or alternatives, since the error
checking is performed in the
constructor, and I must quit the application if the error occurs.
"Jay" <-wrote in message news:%2****************@TK2MSFTNGP03.phx.gbl...
In my C# code, I'm attempting to display a message box then quit the win
form application I'm
writing if a certain type of error occurs when the application starts up.
In the main form's constructor - FormMain() - if this error occurs, I
display a message box then
call Application.Exit().
The problem is that I also need to have some code in my
FormMain_FormClosing event handler, but this
prevents Application.Exit() from quitting the application. Is there
another way of quiting an
application that doesn't call FormMain_FormClosing?