Thread safety on readonly static field initialisation

.NET CLR ensures that static initialization is always thread-safe. No matter how many threads are accessing it and what order, it will always be initialized once.

Your code seems to show signs of the beginnings of a Singleton pattern.
Basically if you want to run custom code before you initialize the class, then you need to ensure thread-safety on your own.
This is an example where you would need to make your custom code thread safe. But the static initialization part is always thread safe.

Leave a Comment