mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-31 02:08:03 +01:00
Revert "Fixes #3520. NetDriver is consuming too much CPU resources in ReadConsoleKeyInfo."
This reverts commit 79192ed8c6.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user