fix: Added critical section to IcdConsole to clean up multi-threaded output

This commit is contained in:
Chris Cameron
2020-10-28 14:42:30 -04:00
parent 64cc662ee7
commit 1e934c9877

View File

@@ -22,6 +22,16 @@ namespace ICD.Common.Utils
public static event EventHandler<StringEventArgs> OnConsolePrint;
private static readonly SafeCriticalSection s_Section;
/// <summary>
/// Static constructor.
/// </summary>
static IcdConsole()
{
s_Section = new SafeCriticalSection();
}
/// <summary>
/// Wraps CrestronConsole.ConsoleCommandResponse for S+ compatibility.
/// </summary>
@@ -64,12 +74,22 @@ namespace ICD.Common.Utils
public static void PrintLine(string message)
{
s_Section.Enter();
try
{
#if SIMPLSHARP
if (IcdEnvironment.RuntimeEnvironment != IcdEnvironment.eRuntimeEnvironment.SimplSharpProServer)
CrestronConsole.PrintLine(message);
#else
Console.WriteLine(message);
#endif
}
finally
{
s_Section.Leave();
}
OnConsolePrint.Raise(null, new StringEventArgs(message + IcdEnvironment.NewLine));
}
@@ -93,12 +113,22 @@ namespace ICD.Common.Utils
public static void Print(string message)
{
s_Section.Enter();
try
{
#if SIMPLSHARP
if (IcdEnvironment.RuntimeEnvironment != IcdEnvironment.eRuntimeEnvironment.SimplSharpProServer)
CrestronConsole.Print(message);
#else
Console.Write(message);
#endif
}
finally
{
s_Section.Leave();
}
OnConsolePrint.Raise(null, new StringEventArgs(message));
}