Use of Program.cs

J

Jeremy

I'm finally getting up to speed on VS 2005 and see that there is now a class
named Program that contains the main entry point for Windows Forms
applications. Yes, I understand that this is something that VS creates for
us and that we are not *required* to use it as is.

My question:
Are many of you who are writing non trivial Windows Forms applications
keeping this Program.cs file as generated by VS? Are you using it "as is" or
do you throw other things in there? If so, what else do you add to
Program.cs?

(just wondering what most developers think of this change and how you are
using it).

Thanks.
 
N

Nicholas Paldino [.NET/C# MVP]

Jeremy,

Personally, I think it is a good thing, as it promotes encapsulation
(why have the startup code in the form? It might not have anything to do
with that).

I will add some code to that file easily, but in general, I think it is
better than the old template.

In the end, it is a class in the project like any other. You can modify
it how you wish.
 
M

Mythran

Jeremy said:
I'm finally getting up to speed on VS 2005 and see that there is now a
class named Program that contains the main entry point for Windows Forms
applications. Yes, I understand that this is something that VS creates for
us and that we are not *required* to use it as is.

My question:
Are many of you who are writing non trivial Windows Forms applications
keeping this Program.cs file as generated by VS? Are you using it "as is"
or do you throw other things in there? If so, what else do you add to
Program.cs?

(just wondering what most developers think of this change and how you are
using it).

Thanks.

When I use VS2K5, I normally either keep Program.cs or change it to
something else (something that I've used is InternalMain, which is just the
same as Program.cs). Inside this class I will normally have any
command-line argument parsing/functionality so that I can just have this
part done with before the rest of the app loads (forms).

But that's just me :)

HTH,
Mythran
 
B

Brian Gideon

Jeremy,

I think it's a good idea. It provides a logical place to put entry
point code. I have since started adopting the convention for 1.1
application as well. I often tinker around with the code inside the
Main method like choosing to run the application as a windows service
or winform application, processing command line arguments, etc.

Brian
 
A

Andy

Yup, except I added a bunch to it, like throwing up a splash screen,
loading some initail data from the database and kicking off some
background threads, all before I show the main form.

When the form closes, it then cleans everything up.

Andy
 
R

Roger

BTW, this is just like the project file in Delphi (dpr).

It is a good clean way to start off and perform
application initialization and precondition checks.

Roger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top