I ac# class library. Is there anyway that a method can be run on first call and only on the first call to the dll? ie. similar to in a web application - global.asax - Application_Start method.
Have a static initializer on your interface object. However, you should only expose this Interface class through your DLL that way, and make all other functional calls internal.
public class DllInterface
{
static DllInterface()
{
// Do initialization magic here
}
// Do other stuff
}
I searched a while for it and found this site . It looks very promising, but i hadn't the time to test it by myself.
(Currently the site is down for maintenance. Here is the site from google cache .)
Interesting question. I don't know if in c# you can do that, but I don't think so. What you can do is to create a static constructor that it will be called before any other call in a class:
public class Foo
{
static Foo()
{
Console.WriteLine("called first time only");
}
public Foo()
{
Console.WriteLine("called every new object");
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.