Re: Application.Exit problem

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 06/17/04


Date: Thu, 17 Jun 2004 20:06:29 +0100

Chuck <ceatley@austin.rr.com> wrote:
> 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.

Well, three options:

1) Don't do the connection within the form construction. Do it before
you construct the form, but while the splash screen is up.

2) Handle the exception so that customers don't see an unhandled
exception. Don't forget that until your constructor has returned,
Application.Run hasn't been called, which is why Application.Exit isn't
working. A simple try/catch in your Main method should work here, I
believe.

3) Use Environment.Exit instead.
 

-- 
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Relevant Pages

  • Re: Existance of a Static variable.
    ... will come into existence even before the static constructor gets ... execution of the static field initializers occurs ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Structured exception information
    ... If there are problems during the execution of the constructor ... How can I pass some error information from the constructor function ... so that it's used when the exception is handled? ...
    (comp.lang.ada)
  • Re: extend prototype chain?
    ... variable instantiation is performed before execution, you can declare ... You technique looks quite useful if we want a fairly generic reviver. ... In case you did not notice, the constructor uses `this' a lot. ... `this' has only meaning in the execution context in which it is used. ...
    (comp.lang.javascript)
  • Re: If you were inventing CoBOL...
    ... but Micro Focus had nearly the same as ... >FILLER ALL TO VALUE" had been executed against it before execution begins. ... a structured constant is a typedef with values. ... like an OO constructor. ...
    (comp.lang.cobol)
  • Re: Inheritance breaks when setting prototype explicitly?
    ... prior to the execution of any code for the global ... When the functions are created their - prototype - properties are set to ... Parent - and - Child - functions but before the assignment of a new ... assigns the value of the constructor function's - prototype - property ...
    (comp.lang.javascript)