From 9a70c1319bb04a2283265404e8da406fb03a5c88 Mon Sep 17 00:00:00 2001 From: Daniel Cazzulino Date: Fri, 25 Oct 2019 13:34:36 -0400 Subject: [PATCH] Avoid throwing when the tokenSource is cancelled (#266) When invoking an action in the main loop, the token will be cancelled (see `MainLoop.Invoke` and `WindowsDriver.Wakeup`). At this point when the EventsPending is running we must avoid throwing by waiting using a cancelled token: `eventReady.Wait(waitTimeout, tokenSource.Token)` And make sure we reach the disposal of the token source. Otherwise we keep throwing over and over and cause a severe performance problem for the running app. --- Terminal.Gui/Drivers/WindowsDriver.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Terminal.Gui/Drivers/WindowsDriver.cs b/Terminal.Gui/Drivers/WindowsDriver.cs index 0c32da6d9..6ad870c92 100644 --- a/Terminal.Gui/Drivers/WindowsDriver.cs +++ b/Terminal.Gui/Drivers/WindowsDriver.cs @@ -504,7 +504,8 @@ namespace Terminal.Gui { waitForProbe.Set(); try { - eventReady.Wait(waitTimeout, tokenSource.Token); + if(!tokenSource.IsCancellationRequested) + eventReady.Wait(waitTimeout, tokenSource.Token); } catch (OperationCanceledException) { return true; } finally {