I want to initialize my C# library as it loads by another process, is it possible and if so - how?
Asked
Active
Viewed 2,527 times
5
-
The CLR does apparently support this, but the compiler does not - see [Module initializers in C#](http://stackoverflow.com/questions/1915506/module-initializers-in-c) – adrianbanks May 30 '10 at 18:42
1 Answers
7
No.
Instead, you can add a static constructor to your class, which will execute the first time that the class is used.

SLaks
- 868,454
- 176
- 1,908
- 1,964
-
1"execute the first time"... make that "execute *before* the first time *any other member is accessed* ". – Richard May 30 '10 at 15:27
-
3because it depends on a class rather than the DLL itself, which is fine and working, but not perfect, not as it suppose to work. – Eran Betzalel May 30 '10 at 22:14