UserMgr是一个普通类, 由于有一个静态字段, 我在静态构造函数中初始化该字段
static UserMgr()
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("thread id:" + Thread.CurrentThread.ManagedThreadId);
Console.WriteLine("appdomain:" + AppDomain.CurrentDomain.FriendlyName);
Console.WriteLine("UserMgr static ctor:" + instanceGuid);
Console.ResetColor();
userDict = ooxx...;
}
后来发现, userDict这个静态字段在运行的时候居然有多份实例
跟着发现
静态构造函数被调用了两次,分别是
thread id:15
appdomain:HostDomain
UserMgr static ctor:da5fe1f6-9523-41be-b4f8-a88aa72085c2
thread id:13
appdomain:HostDomain
UserMgr static ctor:c9503d51-af87-436e-a666-6623ad96a3fc
请教大家可能是什么原因造成的呢?
我知道如果多个域的话,肯定会是多个实例, 但现在域的话我可以保证是同一个域, 该静态字段也没有加[ThreadStatic]特性,
请问还有什么原因会导致静态构造函数调用多次呢?