gui-cs / Terminal.Gui

Cross Platform Terminal UI toolkit for .NET
MIT License
9.73k stars 695 forks source link

Adding a Timeout hammers CPU even when it is not due #3812

Open tznind opened 2 weeks ago

tznind commented 2 weeks ago

Describe the bug

Check timers code returns true if there are any timers even if they are not due. This causes EventsPending to return true with no blocking so main loop iteration will run away with CPU.

_mainLoop.CheckTimersAndIdleHandlers (out int waitTimeout)

runaway-cpu Adding a timeout causes CPU to go up massively

To Reproduce Add any timeout

        Application.AddTimeout (TimeSpan.FromMinutes (32),
                                () =>
                                {
                                    Debug.Write ("heya");

                                    return true;
                                });

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context Add any other context about the problem here.

Set Project & Milestone If you have access, please don't forget to set the right Project and Milestone.

tznind commented 2 weeks ago

It affects idle to which is used internally by WindowsDriver here:

// TODO: This makes ConsoleDriver dependent on Application, which is not ideal. This should be moved to Application.
Application.MainLoop.AddIdle (
                              () =>
                              {
                                  Task.Run (async () => await ProcessContinuousButtonPressedAsync (mouseFlag));

                                  return false;
                              });