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:

  1. Avoid type-loads of any kind in Main. Main should only call methods implemented in the same type definition.
  2. Do not implement a static constructor in the type that contains Main. (Avoiding static fields entirely is the safest way to go).
  3. 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.
  4. 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.
[Via Wintellog]

What others have said

Requesting Gravatar... Michael Weinhardt Apr 24, 2005 4:35 PM
# re: A Stable Application Entry Point - Rethinking "Main()".
One nice feature of VS.NET 2005 is that it conforms to Point 3 when it creates a new WinForms project; the static Main method is deployed within a separate class, Program.

What do you have to say?

(will show your gravatar)
Please add 3 and 6 and type the answer here: