@@ -22,7 +22,7 @@ public static Dictionary<string, string> Read(string filePath)
2222 return properties ;
2323 }
2424
25- var lines = File . ReadAllLines ( filePath , Encoding . UTF8 ) ;
25+ var lines = ReadAllLinesShared ( filePath , Encoding . UTF8 ) ;
2626 foreach ( var line in lines )
2727 {
2828 var trimmed = line . Trim ( ) ;
@@ -48,7 +48,7 @@ public static void Write(string filePath, Dictionary<string, string> properties)
4848
4949 if ( File . Exists ( filePath ) )
5050 {
51- existingLines . AddRange ( File . ReadAllLines ( filePath , Encoding . UTF8 ) ) ;
51+ existingLines . AddRange ( ReadAllLinesShared ( filePath , Encoding . UTF8 ) ) ;
5252 }
5353
5454 var newLines = new List < string > ( ) ;
@@ -114,4 +114,17 @@ private static string ExtractInlineComment(string line)
114114 var match = InlineCommentRegex . Match ( valuePortion ) ;
115115 return match . Success ? match . Groups [ "comment" ] . Value : string . Empty ;
116116 }
117+
118+ private static string [ ] ReadAllLinesShared ( string filePath , Encoding encoding )
119+ {
120+ var lines = new List < string > ( ) ;
121+ using var fs = new FileStream ( filePath , FileMode . Open , FileAccess . Read , FileShare . ReadWrite ) ;
122+ using var reader = new StreamReader ( fs , encoding ) ;
123+ string ? line ;
124+ while ( ( line = reader . ReadLine ( ) ) != null )
125+ {
126+ lines . Add ( line ) ;
127+ }
128+ return lines . ToArray ( ) ;
129+ }
117130}
0 commit comments