diff --git a/src/Impostor.Server/Input/ConsoleInputService.cs b/src/Impostor.Server/Input/ConsoleInputService.cs
index 24e92d0ce..e3c7e8245 100644
--- a/src/Impostor.Server/Input/ConsoleInputService.cs
+++ b/src/Impostor.Server/Input/ConsoleInputService.cs
@@ -36,7 +36,19 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
try
{
- var line = _susLine?.ReadLine(stoppingToken) ?? Console.ReadLine();
+ string? line;
+
+ if (_config.SusLine)
+ {
+ line = await _susLine!.ReadLineAsync(stoppingToken);
+ }
+ else
+ {
+ var task = Task.Run(Console.ReadLine, stoppingToken);
+ await Task.WhenAny(task, Task.Delay(Timeout.Infinite, stoppingToken));
+
+ line = task.IsCompleted ? task.GetAwaiter().GetResult() : null;
+ }
if (string.IsNullOrEmpty(line))
{
diff --git a/src/Impostor.Server/Input/SusLine.cs b/src/Impostor.Server/Input/SusLine.cs
index e1b9aff60..7a3505b2e 100644
--- a/src/Impostor.Server/Input/SusLine.cs
+++ b/src/Impostor.Server/Input/SusLine.cs
@@ -4,6 +4,7 @@
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
+using System.Threading.Tasks;
namespace Impostor.Server.Input
{
@@ -29,7 +30,7 @@ public SusLine()
///
/// for a while loop.
/// The next line of characters from the input stream, or null if no more lines are available.
- public string? ReadLine(CancellationToken stoppingToken)
+ public async ValueTask ReadLineAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
@@ -38,7 +39,7 @@ public SusLine()
continue;
}
- var keyInfo = Console.ReadKey(true);
+ var keyInfo = await Task.Factory.StartNew(static _ => Console.ReadKey(true), this, stoppingToken, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
switch (keyInfo.Key)
{