Quick question on startup logic

S

Simon Harvey

Hi all,

I was wondering how most developers handle the initial startup of their
Windows Forms applications?

When you make an application in Visual Studio, the IDE places Main in the
form that VS makes for you. When I make my applications I sometimes feel
uneasy about leaving the startup logic in the Form - it sort of seems the
wrong place for it. I'm by no means an expert on such things (which is why
I'm writing this post), but it seems that a Form, as part of the UI Layer,
is the wrong place to start an application.

I have tended to try and make a 'main' class that contains the Main() method
and controls the startup of application wide services from there. Thats
causing me some problems though because I don't fully understand what is
best practice when it comes to architecting medium sized application.

So, my question is - where should startup logic go? Am I right to be
suspicious of putting this sort of global logic in the UI layer, or am I way
off the mark and shouldnt be worrying about it?

Your advice as always, would be greatfully received

Many thanks everyone

Simon
 
N

Nicholas Paldino [.NET/C# MVP]

Simon,

I think you are on the right track. For any kind of configuration, etc,
etc, a separate class seems (to me) to be the right way to go. Any class
can have a Main method that is used as the entry point (it doesn't even have
to be called Main, it just has to have a certain signature). For
large-scale apps, I think that it is better to have it in another class to
separate the UI from the buisness logic. Then, you can do your startup, and
pass along any information the form needs to it when you feel it is
appropriate. Also, before the form is shown, this is the perfect place to
do things such as check dependencies, pre-load data, etc, etc (if that is
what you are trying to achieve).

Hope this helps.
 

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