Browse Source

Forgot to use _waitForInput.Reset and remove unnecessary finally block.

BDisp 8 months ago
parent
commit
3425c5a30d
1 changed files with 12 additions and 9 deletions
  1. 12 9
      Terminal.Gui/ConsoleDrivers/WindowsDriver/WindowsMainLoop.cs

+ 12 - 9
Terminal.Gui/ConsoleDrivers/WindowsDriver/WindowsMainLoop.cs

@@ -156,7 +156,16 @@ internal class WindowsMainLoop : IMainLoopDriver
             {
             {
                 if (_inputHandlerTokenSource.IsCancellationRequested && !_forceRead)
                 if (_inputHandlerTokenSource.IsCancellationRequested && !_forceRead)
                 {
                 {
-                    ((IMainLoopDriver)this)._waitForInput.Wait (_inputHandlerTokenSource.Token);
+                    try
+                    {
+                        ((IMainLoopDriver)this)._waitForInput.Wait (_inputHandlerTokenSource.Token);
+                    }
+                    catch (OperationCanceledException)
+                    {
+                        return;
+                    }
+
+                    ((IMainLoopDriver)this)._waitForInput.Reset ();
                 }
                 }
 
 
                 if (_resultQueue?.Count == 0 || _forceRead)
                 if (_resultQueue?.Count == 0 || _forceRead)
@@ -168,19 +177,13 @@ internal class WindowsMainLoop : IMainLoopDriver
                         _resultQueue!.Enqueue (result.Value);
                         _resultQueue!.Enqueue (result.Value);
                     }
                     }
                 }
                 }
-
             }
             }
             catch (OperationCanceledException)
             catch (OperationCanceledException)
             {
             {
                 return;
                 return;
             }
             }
-            finally
-            {
-                if (_inputHandlerTokenSource is { IsCancellationRequested: false })
-                {
-                    _eventReady.Set ();
-                }
-            }
+
+            _eventReady.Set ();
         }
         }
     }
     }