Solved

Class Library - Call Method when main app starts

Posted on 2010-08-19
6
459 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
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.

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now