33using System ;
44using System . Collections . Concurrent ;
55using System . Collections . Generic ;
6+ using System . Diagnostics ;
67using System . Linq ;
78using System . Linq . Expressions ;
89using System . Runtime . CompilerServices ;
@@ -33,7 +34,10 @@ public class TypeAdapterConfig : ITypeAdapterConfig, IConfigConcurrency
3334
3435 [ AdaptIgnore ]
3536 public AutoResetEvent Configure { get ; private set ; }
36-
37+
38+ [ AdaptIgnore ]
39+ public AutoResetEvent ApplySync { get ; private set ; }
40+
3741 internal TypeAdapterConfig ( bool IsGlobal ) : this ( )
3842 {
3943 IsGlobalSettings = IsGlobal ;
@@ -42,6 +46,7 @@ internal TypeAdapterConfig(bool IsGlobal) : this()
4246 public TypeAdapterConfig ( )
4347 {
4448 Configure = new ( true ) ;
49+ ApplySync = new ( true ) ;
4550 Rules = TypeAdapterConfigFactory . RulesTemplate . ToList ( ) ;
4651 var settings = new TypeAdapterSettings ( ) ;
4752 ConfigCompile = new ConfigCompileStorage ( this ) ;
@@ -85,6 +90,11 @@ public LambdaExpression CreateMapExpression(TypeTuple tuple, MapType mapType)
8590 {
8691 Configure . WaitOne ( - 1 ) ;
8792 }
93+ if ( this is IConfigConcurrency config )
94+ {
95+ if ( config . IsScanConcurrency )
96+ ApplySync . WaitOne ( - 1 ) ;
97+ }
8898
8999 var context = new CompileContext ( this ) ;
90100 context . Running . Add ( tuple ) ;
@@ -105,6 +115,7 @@ public LambdaExpression CreateMapExpression(TypeTuple tuple, MapType mapType)
105115 finally
106116 {
107117 Configure . Set ( ) ;
118+ ApplySync . Set ( ) ;
108119
109120 if ( fork != null )
110121 context . Configs . Pop ( ) ;
@@ -175,10 +186,14 @@ public void CompileProjection(Type sourceType, Type destinationType)
175186 /// <param name="registers">collection of IRegister interface to apply mapping.</param>
176187 public void Apply ( IEnumerable < IRegister > registers )
177188 {
189+ ApplySync . WaitOne ( - 1 , false ) ;
190+
178191 foreach ( IRegister register in registers )
179192 {
180193 register . Register ( this ) ;
181194 }
195+
196+ ApplySync . Set ( ) ;
182197 }
183198
184199 /// <summary>
0 commit comments