Skip to content

V1: MainLoop.Invoke causes 1 CPU core consumption on Linux and macOS #3018

@AndreyAkinshin

Description

@AndreyAkinshin

Describe the bug
After the first call of MainLoop.Invoke, the application starts consuming 1 CPU core (100%) on Linux and macOS.

To Reproduce
Steps to reproduce the behavior:

  1. Install .NET SDK 8.0.100 on Linux or macOS
  2. Create a new .NET 8 Console Application: dotnet new console -f net8.0
  3. Install Terminal.Gui 1.14.1: dotnet add package Terminal.Gui --version 1.14.1
  4. Put the following code in Program.cs:
using Terminal.Gui;

Application.Run<MyWindow>();
Application.Shutdown();

public class MyWindow : Window
{
    public MyWindow()
    {
        Application.MainLoop.Invoke(() => { });
    }
}
  1. Run the program: dotnet run
  2. Check out the processes with the highest CPU usage: ps -eo pid,%cpu,command -r | head
  3. You should see your freshly running application with CPU usage of ~100%

Expected behavior
MainLoop.Invoke should not cause stable CPU usage. Before the first call of MainLoop.Invoke, the application CPU usage is quite low, which is also the expected behavior for the application after this call.

Environment
OS: Linux, macOS
Checked Terminal.Gui versions: 1.13.5, 1.14.1
Checked .NET versions: 7.0.14, 8.0.0

Screenshots
I have used Rider to get a dotTrace performance snapshot. Here are the corresponding screenshots:

Timeline:
image

Tracing:
image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    ✅ Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions