A Stable Application Entry Point - Rethinking "Main()".

0 comments suggest edit

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]

Found a typo or error? Suggest an edit! If accepted, your contribution is listed automatically here.



One response

  1. Avatar for Michael Weinhardt
    Michael Weinhardt April 24th, 2005

    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.