Revert "Fixes #3520. NetDriver is consuming too much CPU resources in ReadConsoleKeyInfo."

This reverts commit 79192ed8c6.
This commit is contained in:
BDisp
2024-05-31 23:08:23 +01:00
parent 3b5c1100c3
commit cf001fc0c3

View File

@@ -160,7 +160,8 @@ internal class NetEvents : IDisposable
public InputResult? DequeueInput ()
{
while (_inputReadyCancellationTokenSource is { Token.IsCancellationRequested: false })
while (_inputReadyCancellationTokenSource != null
&& !_inputReadyCancellationTokenSource.Token.IsCancellationRequested)
{
_waitForStart.Set ();
_winChange.Set ();
@@ -198,17 +199,22 @@ internal class NetEvents : IDisposable
private static ConsoleKeyInfo ReadConsoleKeyInfo (CancellationToken cancellationToken, bool intercept = true)
{
// The Console.KeyAvailable must only be used if
// the console is reading an Ansi escape sequence
// Task.Delay must only be used on limited situations
// and not for the entire application execution, which
// case need to use async Task to really awaiting,
// like the CheckWindowSizeChange is using
try
// if there is a key available, return it without waiting
// (or dispatching work to the thread queue)
if (Console.KeyAvailable)
{
return Console.ReadKey (intercept);
}
catch (InvalidOperationException) { }
while (!cancellationToken.IsCancellationRequested)
{
Task.Delay (100);
if (Console.KeyAvailable)
{
return Console.ReadKey (intercept);
}
}
cancellationToken.ThrowIfCancellationRequested ();
@@ -304,10 +310,7 @@ internal class NetEvents : IDisposable
break;
}
if (consoleKeyInfo != default (ConsoleKeyInfo))
{
ProcessMapConsoleKeyInfo (consoleKeyInfo);
}
ProcessMapConsoleKeyInfo (consoleKeyInfo);
break;
}