Peter Duniho said:
As far as I understand it, there's "orderly" and then there's _orderly_.
I take as granted that Environment.Exit() isn't going to leave managed
stuff hanging, but it doesn't know anything about the logic or data of the
application itself. I wouldn't use exit() as a normal strategy for
exiting an unmanaged Windows application, and I wouldn't use
Environment.Exit() as a normal strategy for exiting a managed Windows
application.
Pete
Oh, but I'm not promoting this as a "normal strategy" to end an application,
and IMO this is not what the OP is after, why would he otherwise need to end
an application while handling a form_load event?.
Anyway, with Environment.Exit, there is always a possibility to perform some
"application state clean-up" by registering an AppDomain.ProcessExit event
handler, this is a reasonable strategy to apply when you have to deal with
situations where you want to terminate a process who's (damaged) state
requires it to terminate as soon as possible . This handler will be called
as a last chance to run some managed code (time constrained to a max. of 3
seconds per AppDomain), before the managed environments starts it's orderly
shutdown activity, which consists in starting the GC and the finalizer
thread and give him a reasonable chance to run the reachable and unreachable
Finalizers. So, IMO you have a fair chance to clean-up after you, if you
care.
Note that calling exit() now ((since msvcrt v 7.1 (net 1.1) ),redirects the
call into Environment.Exit whenever called from a process that runs managed
code, this is done to make it possible to start an "orderly shutdown" from a
unmanaged code.
Willy.