Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Holding scroll-bar gets command prompt to pause in Windows

I have a program where I record data through an ADC system from National Instruments (NI).

The device buffers information for some time, and then the program collects the buffer data at some point. If the program collects data larger than the buffer, then the buffer would have to free without my program receiving the data, which will cause the NI library to throw an exception saying that requested data isn't available anymore, since it was lost.

Since my program is a command-prompt program, if the user clicks and holds the scrollbar, the program pauses, which could get this problem to happen.

How can I get over this problem without increasing the buffer size? Can I disable this holding thing in Windows?

Thanks.

like image 408
The Quantum Physicist Avatar asked Feb 12 '13 17:02

The Quantum Physicist


People also ask

How do I stop the command prompt from scrolling?

Disable Scroll-Forward in Command Prompt on Windows Right-click on the title bar of the Command Prompt window. Click on the Properties option. Access Terminal tab in Properties window. Select Disable Scroll-Forward option.

How do I scroll through a command window?

Right click on the title bar of the command window and select properties and select tab layout. A scroll bar will be shown when screen buffer size is bigger then the windows size.

Why does command prompt get stuck?

The issue ended up being a new feature of the windows 10 console. Under the default config, whenever you click on a command window in windows 10, it immediately halts the application process when it attempts to write to the console. When this happens, the command window has gone into "selection" mode.


1 Answers

Only the thread that is attempting to output to the console is blocked. Make this a separate thread, and your problem goes away.

Of course, you'll need to buffer up your output, and do something sensible if the buffer overflows.

For reference, here's the simple code I used to test this, you will note that the counter continues to increase even when the scroll bar is held down:

#include <Windows.h>
#include <stdio.h>

volatile int n = 0;

DWORD WINAPI my_thread(LPVOID parameter)
{
    for (;;)
    {
        n = n + 1;
        Sleep(800);
    }
}

int main(int argc, char ** argv)
{
    if (!CreateThread(NULL, 0, my_thread, NULL, 0, NULL))
    {
        printf("Error %u from CreateThread\n", GetLastError());
        return 0;
    }
    for (;;)
    {
        printf("Hello!  We're at %u\n", n);
        Sleep(1000);
    }
    return 0;
}
like image 59
Harry Johnston Avatar answered Sep 22 '22 21:09

Harry Johnston