这是我正在研究的真实代码的最小(和简化)重现,因为它导致了死锁。有OuterClass一些嵌套类,它们通过外部类的初始化进行初始化(并加载一些数据)。重要的是,一旦对象初始化,数据就可用。
public class OuterClass
{
static ILogger Log = LogManager.GetLogger("OuterClass");
private static InnerClass _innerClass;
public static OuterClass Instance { get; private set; }
private OuterClass()
{
Log.Debug("Constructor called");
_innerClass = new InnerClass();
}
static OuterClass()
{
Instance = new OuterClass();
}
public class InnerClass
{
// using it's own logger, it will not dead lock
//static ILogger Log = LogManager.GetLogger("InnerClass");
private String _data;
public InnerClass()
{
LoadOrUpdateDataAsync().Wait(); // will make the second Log.Debug call dead lock
//_ = …Run Code Online (Sandbox Code Playgroud)