From d4e2dbb4b1cba6f7dfe73aa674c66f3c2c71b42f Mon Sep 17 00:00:00 2001 From: Glax Date: Wed, 3 Jan 2024 20:06:43 +0100 Subject: [PATCH] Return Task to keep GC from collecting the consoleOutput --- OSCCollar/ConsoleOutput.cs | 6 ++++-- OSCCollar/OSCCollar.cs | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/OSCCollar/ConsoleOutput.cs b/OSCCollar/ConsoleOutput.cs index 60e3fcf..155928a 100644 --- a/OSCCollar/ConsoleOutput.cs +++ b/OSCCollar/ConsoleOutput.cs @@ -5,7 +5,7 @@ namespace VRC_Console; public partial class OSCCollar { private const byte CoordinateSystemSize = 16; - private void SetupConsoleOutput() + private Task SetupConsoleOutput() { Layout layout = new Layout().SplitRows( new Layout("Top"), @@ -14,6 +14,8 @@ public partial class OSCCollar new Layout("Variable-Values"), new Layout("Position") )); + if(OperatingSystem.IsWindows()) + Console.WindowWidth += 20; Table configTable = new Table(); configTable.AddColumn("ConVar"); configTable.AddColumn("Value"); @@ -45,7 +47,7 @@ public partial class OSCCollar variableTable.AddRow("CalibrationX", ""); variableTable.AddRow("CalibrationY", ""); - AnsiConsole.Live(layout).StartAsync(async displayContext => + return AnsiConsole.Live(layout).StartAsync(async displayContext => { while (true) { diff --git a/OSCCollar/OSCCollar.cs b/OSCCollar/OSCCollar.cs index 40ddbe8..f7ed980 100644 --- a/OSCCollar/OSCCollar.cs +++ b/OSCCollar/OSCCollar.cs @@ -36,6 +36,7 @@ public partial class OSCCollar private OSCQueryService? OscQueryService { get; set; } private OscServer _server = null!; private OscClient _client = null!; + private Task _consoleOutputTask; private float _leashStretch; private readonly Vector _unitVectorLeash = new(1, 0); @@ -68,7 +69,7 @@ public partial class OSCCollar this._portReceive = Extensions.GetAvailableUdpPort(); this.SetupOSCServer(); this.SetupOSCQuery(); - this.SetupConsoleOutput(); + this._consoleOutputTask = this.SetupConsoleOutput(); } private OSCCollar(string ip = "127.0.0.1", int portSend = 9000, double radius = 100, double calibrationX = 0,