C# Can the Console overflow with too many Writelines?

LT Dan picture LT Dan · Jul 6, 2012 · Viewed 7.3k times · Source

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.

Answer

Richard Ev picture Richard Ev · Jul 6, 2012

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).