cmd

Windows pauses my program when I run it from cmd and leave the window idle. How do I tell it not to?


I've written a simple application in C that is quite CPU intensive. I run it from a command line, e.g. ".\my_program.exe". I have noticed that when I leave the computer idle, sometimes even if I just focus away from the cmd window, the process effectively pauses. When I click on the cmd window, it resumes regular progress again.

Is there a way I can instruct windows to prioritise such a command?


Solution

  • That is probably happening because of "Quick Edit Mode", as said "Stephan" on the question's comments. Since you are using C, you can deactivate it using the Win32 API, as follows.

    HADNLE handle_input;
    DWORD console_mode;
    handle_input = GetStdHandle(STD_INPUT_HANDLE);
    
    GetConsoleMode(handle_input, &console_mode);
    console_mode &= ~ENABLE_QUICK_EDIT_MODE;
    console_mode |= ENABLE_EXTENDED_FLAGS;
    SetConsoleMode(handle_input, console_mode);
    

    You can also do it manually for a CMD instance, by the following steps. If you want to change the default, just click "Default" instead of "Properties".

    1. Click with the right mouse button on the title bar.
    2. Click on "Properties".
    3. On the menu "Options", toggle the checkbox named "Quick Edit Mode".

    UPDATE At the request of the answerer @Schilive I am adding screenshots of the mystifying Settings menu in Windows 11 where I don't see Quick Edit Mode anywhere. --@BobStein

    how to get to the "Settings" menu

    the Settings menu "Interaction" tab