浏览代码

Improving performance on CheckWindowSizeChange.

BDisp 1 年之前
父节点
当前提交
8c500fcbb7
共有 1 个文件被更改,包括 25 次插入25 次删除
  1. 25 25
      Terminal.Gui/ConsoleDrivers/NetDriver.cs

+ 25 - 25
Terminal.Gui/ConsoleDrivers/NetDriver.cs

@@ -328,14 +328,36 @@ internal class NetEvents : IDisposable
         }
     }
 
-    private void CheckWindowSizeChange ()
+    private async Task CheckWindowSizeChange ()
     {
-        void RequestWindowSize (CancellationToken cancellationToken)
+        while (true)
+        {
+            if (_inputReadyCancellationTokenSource.IsCancellationRequested)
+            {
+                return;
+            }
+
+            try
+            {
+                _winChange.Wait (_inputReadyCancellationTokenSource.Token);
+                _winChange.Reset ();
+
+                await RequestWindowSize (_inputReadyCancellationTokenSource.Token);
+            }
+            catch (OperationCanceledException)
+            {
+                return;
+            }
+
+            _inputReady.Set ();
+        }
+
+        async Task RequestWindowSize (CancellationToken cancellationToken)
         {
             while (!cancellationToken.IsCancellationRequested)
             {
                 // Wait for a while then check if screen has changed sizes
-                Task.Delay (500, cancellationToken);
+                await Task.Delay (500, cancellationToken);
 
                 int buffHeight, buffWidth;
 
@@ -363,28 +385,6 @@ internal class NetEvents : IDisposable
 
             cancellationToken.ThrowIfCancellationRequested ();
         }
-
-        while (true)
-        {
-            if (_inputReadyCancellationTokenSource.IsCancellationRequested)
-            {
-                return;
-            }
-
-            try
-            {
-                _winChange.Wait (_inputReadyCancellationTokenSource.Token);
-                _winChange.Reset ();
-
-                RequestWindowSize (_inputReadyCancellationTokenSource.Token);
-            }
-            catch (OperationCanceledException)
-            {
-                return;
-            }
-
-            _inputReady.Set ();
-        }
     }
 
     /// <summary>Enqueue a window size event if the window size has changed.</summary>