Initializing ThreadStatic field still causes NullReferenceException
问题 I've written myself a multi-threaded random generator public static class MyRandGen { private static Random GlobalRandom = new Random(); [ThreadStatic] private static Random ThreadRandom = new Random(SeedInitializer()); private static int SeedInitializer() { lock (GlobalRandom) return GlobalRandom.Next(); } public static int Next() { return ThreadRandom.Next(); } } However, it throws me a NullReferenceException on firing Next(), which I don't understand. Is that kind of initializing