From f0a079b242f69cf3a92b618771b8d20c8aeef8e2 Mon Sep 17 00:00:00 2001 From: giladlevi Date: Fri, 25 Oct 2019 20:29:16 +0300 Subject: [PATCH] [Re]move unwanted allocation (new CancellationTokenSource()) in WindowsDriver.EventsPending to only when needed (#274) --- Terminal.Gui/Drivers/WindowsDriver.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Terminal.Gui/Drivers/WindowsDriver.cs b/Terminal.Gui/Drivers/WindowsDriver.cs index 82a20374b..85745407a 100644 --- a/Terminal.Gui/Drivers/WindowsDriver.cs +++ b/Terminal.Gui/Drivers/WindowsDriver.cs @@ -503,8 +503,7 @@ namespace Terminal.Gui { result = null; waitForProbe.Set(); - tokenSource.Dispose(); - tokenSource = new CancellationTokenSource(); + try { eventReady.Wait(waitTimeout, tokenSource.Token); } catch (OperationCanceledException) { @@ -513,7 +512,13 @@ namespace Terminal.Gui { eventReady.Reset(); } Debug.WriteLine("Events ready"); - return result != null || tokenSource.IsCancellationRequested; + + if (!tokenSource.IsCancellationRequested) + return result != null; + + tokenSource.Dispose(); + tokenSource = new CancellationTokenSource(); + return true; } Action keyHandler;