浏览代码

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.
Daniel Cazzulino 5 年之前
父节点
当前提交
9a70c1319b
共有 1 个文件被更改,包括 2 次插入1 次删除
  1. 2 1
      Terminal.Gui/Drivers/WindowsDriver.cs

+ 2 - 1
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 {