@@ -8,7 +8,8 @@ namespace InEngine.Core.IO
88{
99 public class Write : IWrite
1010 {
11- static Mutex mutexLock = new Mutex ( ) ;
11+ static Mutex consoleOutputLock = new Mutex ( ) ;
12+ static Mutex fileOutputLock = new Mutex ( ) ;
1213
1314 public ConsoleColor InfoColor { get ; set ; } = ConsoleColor . Green ;
1415 public ConsoleColor WarningColor { get ; set ; } = ConsoleColor . Yellow ;
@@ -45,11 +46,11 @@ public IWrite Line(string val)
4546
4647 public IWrite ColoredLine ( string val , ConsoleColor consoleColor )
4748 {
48- mutexLock . WaitOne ( ) ;
49+ consoleOutputLock . WaitOne ( ) ;
4950 Console . ForegroundColor = consoleColor ;
5051 Console . WriteLine ( val ) ;
5152 Console . ResetColor ( ) ;
52- mutexLock . ReleaseMutex ( ) ;
53+ consoleOutputLock . ReleaseMutex ( ) ;
5354 Buffer . Add ( val ) ;
5455 return this ;
5556 }
@@ -76,11 +77,11 @@ public IWrite Text(string val)
7677
7778 public IWrite ColoredText ( string val , ConsoleColor consoleColor )
7879 {
79- mutexLock . WaitOne ( ) ;
80+ consoleOutputLock . WaitOne ( ) ;
8081 Console . ForegroundColor = consoleColor ;
8182 Console . Write ( val ) ;
8283 Console . ResetColor ( ) ;
83- mutexLock . ReleaseMutex ( ) ;
84+ consoleOutputLock . ReleaseMutex ( ) ;
8485 Buffer . Add ( val ) ;
8586 return this ;
8687 }
@@ -94,12 +95,14 @@ public string FlushBuffer()
9495
9596 public void ToFile ( string path , string text , bool shouldAppend = false )
9697 {
98+ fileOutputLock . WaitOne ( ) ;
9799 if ( ! File . Exists ( path ) )
98100 File . Create ( path ) ;
99101 if ( shouldAppend )
100102 File . AppendAllText ( path , text ) ;
101103 else
102104 File . WriteAllText ( path , text ) ;
105+ fileOutputLock . ReleaseMutex ( ) ;
103106 }
104107 }
105108}
0 commit comments