@@ -50,6 +50,7 @@ internal static class Global
50
50
51
51
internal static readonly AsyncLockQueueDictionary < string > FileOperationLocks = new AsyncLockQueueDictionary < string > ( ) ;
52
52
//internal static readonly AsyncLock FileOperationAsyncLock = new AsyncLock();
53
+ internal static readonly AsyncSemaphore FileOperationSemaphore = new AsyncSemaphore ( 2 ) ; //allow 2 concurrent file synchronisations: while one is finishing the write, the next one can start the read
53
54
}
54
55
#pragma warning restore S2223
55
56
@@ -607,35 +608,38 @@ public static async Task FileUpdated(string fullName, Context context)
607
608
var otherFullName = GetOtherFullName ( fullName ) ;
608
609
using ( await Global . FileOperationLocks . LockAsync ( fullName , otherFullName , context . Token ) )
609
610
{
610
- var fullNameInvariant = fullName . ToUpperInvariantOnWindows ( Global . CaseSensitiveFilenames ) ;
611
-
612
- if (
613
- Global . WatchedCodeExtension . Any ( x => fullNameInvariant . EndsWith ( "." + x ) )
614
- || Global . WatchedCodeExtension . Contains ( "*" )
615
- )
611
+ using ( await Global . FileOperationSemaphore . LockAsync ( ) )
616
612
{
617
- if ( fullNameInvariant . StartsWith ( Extensions . GetLongPath ( Global . AsyncPath ) ) )
618
- {
619
- await AsyncToSyncConverter . AsyncFileUpdated ( fullName , context ) ;
620
- }
621
- else if ( IsSyncPath ( fullNameInvariant ) ) //NB!
622
- {
623
- await SyncToAsyncConverter . SyncFileUpdated ( fullName , context ) ;
624
- }
625
- else
613
+ var fullNameInvariant = fullName . ToUpperInvariantOnWindows ( Global . CaseSensitiveFilenames ) ;
614
+
615
+ if (
616
+ Global . WatchedCodeExtension . Any ( x => fullNameInvariant . EndsWith ( "." + x ) )
617
+ || Global . WatchedCodeExtension . Contains ( "*" )
618
+ )
626
619
{
627
- throw new ArgumentException ( "fullName" ) ;
620
+ if ( fullNameInvariant . StartsWith ( Extensions . GetLongPath ( Global . AsyncPath ) ) )
621
+ {
622
+ await AsyncToSyncConverter . AsyncFileUpdated ( fullName , context ) ;
623
+ }
624
+ else if ( IsSyncPath ( fullNameInvariant ) ) //NB!
625
+ {
626
+ await SyncToAsyncConverter . SyncFileUpdated ( fullName , context ) ;
627
+ }
628
+ else
629
+ {
630
+ throw new ArgumentException ( "fullName" ) ;
631
+ }
628
632
}
629
- }
630
- else //Assume ResX file
631
- {
632
- var fileData = await FileExtensions . ReadAllBytesAsync ( Extensions . GetLongPath ( fullName ) , context . Token ) ;
633
- var originalData = fileData ;
633
+ else //Assume ResX file
634
+ {
635
+ var fileData = await FileExtensions . ReadAllBytesAsync ( Extensions . GetLongPath ( fullName ) , context . Token ) ;
636
+ var originalData = fileData ;
634
637
635
- //save without transformations
636
- await ConsoleWatch . SaveFileModifications ( fullName , fileData , originalData , context ) ;
637
- }
638
- }
638
+ //save without transformations
639
+ await ConsoleWatch . SaveFileModifications ( fullName , fileData , originalData , context ) ;
640
+ }
641
+ } //using (await Global.FileOperationSemaphore.LockAsync())
642
+ } //using (await Global.FileOperationLocks.LockAsync(fullName, otherFullName, context.Token))
639
643
}
640
644
} //public static async Task FileUpdated(string fullName, Context context)
641
645
0 commit comments