Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -709,9 +709,14 @@ private void WriteLineToConsole()
/// </exception>
public override void Write(string value)
{
WriteImpl(value, newLine: false);
lock (_instanceLock)
{
WriteImpl(value, newLine: false);
}
}

// The WriteImpl() method should always be called within a lock on _instanceLock
// to ensure thread safety and prevent issues in multi-threaded scenarios.
private void WriteImpl(string value, bool newLine)
{
if (string.IsNullOrEmpty(value) && !newLine)
Expand Down Expand Up @@ -845,7 +850,10 @@ private void Write(ConsoleColor foregroundColor, ConsoleColor backgroundColor, s
/// </exception>
public override void WriteLine(string value)
{
this.WriteImpl(value, newLine: true);
lock (_instanceLock)
{
this.WriteImpl(value, newLine: true);
}
}

/// <summary>
Expand All @@ -862,7 +870,10 @@ public override void WriteLine(string value)
/// </exception>
public override void WriteLine()
{
this.WriteImpl(Environment.NewLine, newLine: false);
lock (_instanceLock)
{
this.WriteImpl(Environment.NewLine, newLine: false);
}
}

#region Word Wrapping
Expand Down
Loading