Use Stream.Synchronized

This commit is contained in:
Alexey Golub
2020-05-23 18:48:46 +03:00
parent bed22b6500
commit 42f4d7d5a7
2 changed files with 4 additions and 5 deletions

View File

@@ -94,15 +94,14 @@ namespace CliFx
public partial class SystemConsole
{
// TODO: use StreamWriter.Synchronized?
private static StreamReader WrapInput(Stream? stream) =>
stream != null
? new StreamReader(stream, Console.InputEncoding, false)
? new StreamReader(Stream.Synchronized(stream), Console.InputEncoding, false)
: StreamReader.Null;
private static StreamWriter WrapOutput(Stream? stream) =>
stream != null
? new StreamWriter(stream, Console.OutputEncoding) {AutoFlush = true}
? new StreamWriter(Stream.Synchronized(stream), Console.OutputEncoding) {AutoFlush = true}
: StreamWriter.Null;
}
}

View File

@@ -94,12 +94,12 @@ namespace CliFx
{
private static StreamReader WrapInput(Stream? stream) =>
stream != null
? new StreamReader(stream, Console.InputEncoding, false)
? new StreamReader(Stream.Synchronized(stream), Console.InputEncoding, false)
: StreamReader.Null;
private static StreamWriter WrapOutput(Stream? stream) =>
stream != null
? new StreamWriter(stream, Console.OutputEncoding) {AutoFlush = true}
? new StreamWriter(Stream.Synchronized(stream), Console.OutputEncoding) {AutoFlush = true}
: StreamWriter.Null;
}
}