Hi Bob ,
Thanks for your feedback.
Regarding this, why not just return from Main method to exit the
application? This is the graceful and recomanded way of exiting a
thread/application. (Actually, even in C/C++, exit() is not the recommanded
way to exit the thread, because:
"When you call the exit or _exit functions, the destructors for any
temporary or automatic objects that exist at the time of the call are not
called. An automatic object is an object that is defined in a function
where the object is not declared to be static. A temporary object is an
object created by the compiler.", this may cause some inconsistent behavior
or memory leak in the 24X7 server applications.)
Exception is not a recommanded way to jump the execution path; it has some
performance hit, because exception requires some context switch to the
kernel mode.
Yes, I can reproduce out the behavior that Application.Exit() method does
not take effect in this scenario. This is because Application.Exit
internally always check an internal ApplicationContext class, which is
created after invoking Application.Run(). Because your code invokes
Application.Exit before Application.Run, this Application.Exit() method
takes no effect. If you really want to exit the current thread, you may
p/invoke ExitThread Win32 API, however, just as I original stated, it is
not an elegant API, which we should avoid in application. Returning from
Main method in normal flow is the correct way.
Hope this helps!
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.