I can see two obvious sources of threading problems
- What type is
_data
and_isDataLoaded
? If these types are not thread safe then neither is your code arrays are only thread safe if no two threads access the same element, which could happen in the above code. Try using a ConcurrentDictionary instead. - Depending on the exact implementation of
GetCachedConstant
andCacheToFile
there is a potential race condition whereby thread A could begin writing cached data to a file causing thread B to go down theFile.Exists
route when in fact the file only contains partially written data
I'd guess the culprit is the first of these two - there might be other problems but unless these types are thread safe no amount of double checked locking will save you unless you also synchronize access to those objects.