2

I log my messages to the console. But I have some interesting effect. My UI hangs when I select some messages in the console. UI will alive when I deselect all in the console. I do not like such behavior.

Is it any solution?

Console::WriteLine("Message");  
Peter Ritchie
  • 35,463
  • 9
  • 80
  • 98
Voloda2
  • 12,359
  • 18
  • 80
  • 130
  • Does this answer your question? [How to programmatic disable C# Console Application's Quick Edit mode?](https://stackoverflow.com/questions/13656846/how-to-programmatic-disable-c-sharp-console-applications-quick-edit-mode) – Maicon Mauricio Aug 08 '23 at 01:11

3 Answers3

7

You can disable quick edit mode in your console programmatically:

class Program {
    static void Main(string[] args) {
        uint mode;
        IntPtr stdIn = GetStdHandle(STD_INPUT_HANDLE);
        if (GetConsoleMode(stdIn, out mode)) {
            if ((mode & (uint) ConsoleModes.ENABLE_QUICK_EDIT_MODE) != 0) {
                mode = mode ^ (uint) ConsoleModes.ENABLE_QUICK_EDIT_MODE;
                SetConsoleMode(stdIn, mode);
            }
        }
        int i = 0;
        while (true) {
            Thread.Sleep(300);
            Console.WriteLine(i++);
        }
    }
    const int STD_INPUT_HANDLE = -10;
    [DllImport("kernel32.dll", SetLastError = true)]
    static extern IntPtr GetStdHandle(int nStdHandle);
    [DllImport("kernel32.dll")]
    static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint lpMode);
    [DllImport("kernel32.dll")]
    static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint dwMode);
    [Flags()]
    enum ConsoleModes : uint {
        ENABLE_PROCESSED_INPUT = 0x1,
        ENABLE_LINE_INPUT = 0x2,
        ENABLE_ECHO_INPUT = 0x4,
        ENABLE_WINDOW_INPUT = 0x8,
        ENABLE_MOUSE_INPUT = 0x10,
        ENABLE_INSERT_MODE = 0x20,
        ENABLE_QUICK_EDIT_MODE = 0x40,
        ENABLE_EXTENDED_FLAGS = 0x80,
        ENABLE_AUTO_POSITION = 0x100,
    }
}
Alex Butenko
  • 3,664
  • 3
  • 35
  • 54
1

You're selecting text in the console. You can imagine that if the console continued outputting information it would be hard to select what you want to select, so the system pauses visible updates. If you want your application to continuing showing visible updates, stop selecting text on the screen.

Peter Ritchie
  • 35,463
  • 9
  • 80
  • 98
-1

This is not specific to your application, it's "feature" exists for all console applications. When selecting text - the whole application hangs. This behavior can't be changed.

Shahar Gvirtz
  • 2,418
  • 1
  • 14
  • 17