Solved

Class Library - Call Method when main app starts

Posted on 2010-08-19
6
462 Views
Last Modified: 2013-11-07
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 ?
0
Comment
Question by:eguilherme
6 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 33475251
>>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.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 33475516
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.
0
 
LVL 3

Expert Comment

by:kooswillem
ID: 33476235
Why don't you just call each of the methods in the classes from your main class at application start?
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 10

Author Comment

by:eguilherme
ID: 33477150
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
0
 
LVL 2

Accepted Solution

by:
robertlevy earned 500 total points
ID: 33482899
this type of question often means that what you really need is some refactoring to use a Dependency Injection framework.  see http://visualstudiomagazine.com/Articles/2010/08/01/Inversion-of-Control-Patterns-for-the-Microsoft-NET-Framework.aspx for a good primer on DI
0
 
LVL 4

Expert Comment

by:fromer
ID: 33483745
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..
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question