Class Library - Call Method when main app starts

Hello, i have a solution with a windows forms app and some additional class library projects..

i want to know if there is anyway to make a method on one of the class library to execute the moment the main application starts without having to manually make the call in the main application..

(so that it wont matter where the class library is referenced it will always execute a method when the main app starts)

is it possible ?
LVL 10
Who is Participating?
robertlevyConnect With a Mentor Commented:
this type of question often means that what you really need is some refactoring to use a Dependency Injection framework.  see for a good primer on DI
AndyAinscowFreelance programmer / ConsultantCommented:
>>is it possible ?

As you describe it I don't think so.  The method would need to be called explicitly somewhere, I haven't heard of an 'autostart' method specifier.
AndyAinscowFreelance programmer / ConsultantCommented:
Or - this might not be suitable: Just use the class via a singleton wrapper class, you can then call this method the very first time the 'real' class is to be used because it is going via this singleton class you have coded.
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Why don't you just call each of the methods in the classes from your main class at application start?
eguilhermeAuthor Commented:
since some of those classes will be in different applications, i would like that they would get called automaticly, instead of having to manually call them at every application..

but i guess its not possible =/

i ll leave this open for now..maybe someone else has an answer
I don't think it's possible. Even static members are initialized just before access..
No way to execute code from class libraries at application start before accessing them..
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.