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.
This commit is contained in:
Daniel Cazzulino
2019-10-25 13:34:36 -04:00
committed by Miguel de Icaza
parent a20d244d59
commit 9a70c1319b

View File

@@ -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 {