private static void WriteToConsole(string message, ConsoleColor? foregroundColor = null,
ConsoleColor? backgroundColor = null, bool line = true)
{
lock (_lock)
{
ConsoleColor? fg = null;
if (foregroundColor.HasValue)
{
fg = Console.ForegroundColor;
Console.ForegroundColor = foregroundColor.Value;
}
ConsoleColor? bg = null;
if (backgroundColor.HasValue)
{
bg = Console.BackgroundColor;
Console.BackgroundColor = backgroundColor.Value;
}
if (line)
Console.WriteLine(message);
else
Console.Write(message);
if (fg.HasValue)
{
Console.ForegroundColor = fg.Value;
}
if (bg.HasValue)
{
Console.BackgroundColor = bg.Value;
}
}
}
}