mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-01-11 19:44:55 +00:00
fix: Added critical section to IcdConsole to clean up multi-threaded output
This commit is contained in:
@@ -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);
|
||||
if (IcdEnvironment.RuntimeEnvironment != IcdEnvironment.eRuntimeEnvironment.SimplSharpProServer)
|
||||
CrestronConsole.PrintLine(message);
|
||||
#else
|
||||
Console.WriteLine(message);
|
||||
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);
|
||||
if (IcdEnvironment.RuntimeEnvironment != IcdEnvironment.eRuntimeEnvironment.SimplSharpProServer)
|
||||
CrestronConsole.Print(message);
|
||||
#else
|
||||
Console.Write(message);
|
||||
Console.Write(message);
|
||||
#endif
|
||||
}
|
||||
finally
|
||||
{
|
||||
s_Section.Leave();
|
||||
}
|
||||
|
||||
OnConsolePrint.Raise(null, new StringEventArgs(message));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user