简体   繁体   中英

Copying and pasting command prompt causes frozen console application to progress

I am writing a console application using Visual Studio and C#. I am constantly printing out debugging information to the console window.

The program is fairly simple, it just queries several databases multiple times and stores the values in my central database. It does this just over 900 times in total. At the point when it is querying the databases, it will occasionally (and randomly) stall on the console window, and ceases to print out debugging information or go any further in the program. The peculiar thing is, when I highlight the window and right click (to copy), this seems to kick the program back into life and it begins to work again!

Does anyone know what could be causing this? It's the most peculiar behaviour I have ever seen in a program before!

If the user accidentally clicks into the black console window, the cursor changes to a filled white rectangle, and the app hangs, until another clic is made.

It is a generic feature of the Console window when its "QuickEdit Mode" is enabled.

In order to disable that feature, you should uncheck the "QuickEdit Mode" option of your app's console window at run-time.

Or disable it programmatically :

// http://msdn.microsoft.com/en-us/library/ms686033(VS.85).aspx
    [DllImport("kernel32.dll")]
    public static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint dwMode);

    private const uint ENABLE_EXTENDED_FLAGS = 0x0080;

    static void Main(string[] args)
    {
         IntPtr handle = Process.GetCurrentProcess().MainWindowHandle;
         SetConsoleMode(handle, ENABLE_EXTENDED_FLAGS);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM