Solved

Class Library - Call Method when main app starts

Posted on 2010-08-19
6
458 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
Comment Utility
>>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
Comment Utility
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
Comment Utility
Why don't you just call each of the methods in the classes from your main class at application start?
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 10

Author Comment

by:eguilherme
Comment Utility
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
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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.

743 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