C# Can the Console overflow with too many Writelines?
Asked Answered
S

3

10

If I have a program that performs Console.Writeline multiple times per second, and the program is left running for a long period of time, can the console overflow with too many lines? I just want to know if it will eventually throw an IO exception or if number of Console.Writelines is virtually infinite.

Shandeigh answered 6/7, 2012 at 13:51 Comment(2)
There must be reason you asked this question, so what is it, people don't ask random questions.Sod
Not really relevant to your question, but thought it would be worth mentioning that it might not be great practise to use Console.Writeline many times per second unless you need to. There is a heavy I/O cost associated with writing to the console which may in fact be slowing your program down.Nail
A
22

No, it won't overflow. If you check the Options tab for a shortcut to the command window you will see a buffer size option. This specifies the maximum number of lines that will be stored. Older ones get deleted.

As Scott suggests in his comment below, you can access this setting from your code using Console.BufferHeight. The default value for this (when I tested on my development PC) is 300. The maximum allowed value is 32766 (Int16.MaxValue - 1).

Apparitor answered 6/7, 2012 at 13:53 Comment(1)
Or just check/set Console.BufferHeightRikkiriksdag
B
4

The console has a buffer of how many lines it keeps, you can set it in the cmd.exe properties:

Cmd.exe properties

So after 300 lines it will forget what was output at line 1.

Brusquerie answered 6/7, 2012 at 13:54 Comment(0)
P
1

the maximum allowed value is 32766 (corrected);

Precipitous answered 6/7, 2012 at 13:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.