[Re]move unwanted allocation (new CancellationTokenSource()) in WindowsDriver.EventsPending to only when needed (#274)

This commit is contained in:
giladlevi
2019-10-25 20:29:16 +03:00
committed by Miguel de Icaza
parent c832688112
commit f0a079b242

View File

@@ -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<KeyEvent> keyHandler;