mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-16 13:15:07 +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;
|
public static event EventHandler<StringEventArgs> OnConsolePrint;
|
||||||
|
|
||||||
|
private static readonly SafeCriticalSection s_Section;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Static constructor.
|
||||||
|
/// </summary>
|
||||||
|
static IcdConsole()
|
||||||
|
{
|
||||||
|
s_Section = new SafeCriticalSection();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Wraps CrestronConsole.ConsoleCommandResponse for S+ compatibility.
|
/// Wraps CrestronConsole.ConsoleCommandResponse for S+ compatibility.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -64,12 +74,22 @@ namespace ICD.Common.Utils
|
|||||||
|
|
||||||
public static void PrintLine(string message)
|
public static void PrintLine(string message)
|
||||||
{
|
{
|
||||||
|
s_Section.Enter();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
#if SIMPLSHARP
|
#if SIMPLSHARP
|
||||||
if (IcdEnvironment.RuntimeEnvironment != IcdEnvironment.eRuntimeEnvironment.SimplSharpProServer)
|
if (IcdEnvironment.RuntimeEnvironment != IcdEnvironment.eRuntimeEnvironment.SimplSharpProServer)
|
||||||
CrestronConsole.PrintLine(message);
|
CrestronConsole.PrintLine(message);
|
||||||
#else
|
#else
|
||||||
Console.WriteLine(message);
|
Console.WriteLine(message);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
s_Section.Leave();
|
||||||
|
}
|
||||||
|
|
||||||
OnConsolePrint.Raise(null, new StringEventArgs(message + IcdEnvironment.NewLine));
|
OnConsolePrint.Raise(null, new StringEventArgs(message + IcdEnvironment.NewLine));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,12 +113,22 @@ namespace ICD.Common.Utils
|
|||||||
|
|
||||||
public static void Print(string message)
|
public static void Print(string message)
|
||||||
{
|
{
|
||||||
|
s_Section.Enter();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
#if SIMPLSHARP
|
#if SIMPLSHARP
|
||||||
if (IcdEnvironment.RuntimeEnvironment != IcdEnvironment.eRuntimeEnvironment.SimplSharpProServer)
|
if (IcdEnvironment.RuntimeEnvironment != IcdEnvironment.eRuntimeEnvironment.SimplSharpProServer)
|
||||||
CrestronConsole.Print(message);
|
CrestronConsole.Print(message);
|
||||||
#else
|
#else
|
||||||
Console.Write(message);
|
Console.Write(message);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
s_Section.Leave();
|
||||||
|
}
|
||||||
|
|
||||||
OnConsolePrint.Raise(null, new StringEventArgs(message));
|
OnConsolePrint.Raise(null, new StringEventArgs(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user