A Stable Application Entry Point - Rethinking "Main()".
Jason Clark enlightens us on creating a stable application entry point at the wintellect blog. I highly recommend reading the whole discussion, but one of the key takeaways is...
A Stable Entry Method
Fortunately it doesn’t take too much effort to make your entry method stable. Here are some guidelines:
- Avoid type-loads of any kind in Main. Main should only call methods implemented in the same type definition.
- Do not implement a static constructor in the type that contains Main. (Avoiding static fields entirely is the safest way to go).
- Derive the type that contains Main from Object. This means that you need to hoist Main out of the type definition for your main form if you use Visual Studio .Net wizards to create your project.
- Keep the type that contains Main focused on getting your application started. Don’t think of it as the “Application” type that holds your application-level state.