@@ -33,6 +33,7 @@ namespace SIL.LCModel.Infrastructure.Impl
3333 internal sealed class CmObjectSurrogate : ICmObjectSurrogate //, IEquatable<CmObjectSurrogate>
3434 {
3535 private static Dictionary < string , ConstructorInfo > s_classToConstructorInfo ;
36+ private static readonly object s_constructorLock = new object ( ) ;
3637 /// <summary>
3738 /// It's common that hundreds of thousands of surrogates only use a few hundred class names. This is a local interning
3839 /// of those names.
@@ -225,16 +226,19 @@ internal static CmObjectSurrogate CreateSnapshot(ICmObject obj)
225226
226227 internal static void InitializeConstructors ( List < Type > cmObjectTypes )
227228 {
228- if ( s_classToConstructorInfo != null ) return ;
229-
230- s_classToConstructorInfo = new Dictionary < string , ConstructorInfo > ( ) ;
231- // Get default constructor.
232- // Only do this once, since they are stored in a static data member.
233- foreach ( var lcmType in cmObjectTypes )
229+ lock ( s_constructorLock )
234230 {
235- if ( lcmType . IsAbstract ) continue ;
231+ if ( s_classToConstructorInfo != null ) return ;
232+
233+ s_classToConstructorInfo = new Dictionary < string , ConstructorInfo > ( ) ;
234+ // Get default constructor.
235+ // Only do this once, since they are stored in a static data member.
236+ foreach ( var lcmType in cmObjectTypes )
237+ {
238+ if ( lcmType . IsAbstract ) continue ;
236239
237- s_classToConstructorInfo . Add ( lcmType . Name , lcmType . GetConstructor ( BindingFlags . Instance | BindingFlags . Public | BindingFlags . NonPublic , null , Type . EmptyTypes , null ) ) ;
240+ s_classToConstructorInfo . Add ( lcmType . Name , lcmType . GetConstructor ( BindingFlags . Instance | BindingFlags . Public | BindingFlags . NonPublic , null , Type . EmptyTypes , null ) ) ;
241+ }
238242 }
239243 }
240244
0 commit comments