I’m writing data to a log file and need to display that data in my WinForms UI. My initial thought was to use a multiline textbox like this:
private void UpdateUITextbox(string text)
{
textBoxStatus.AppendText(text + Environment.NewLine);
}
I don’t write a huge amount of text to my log file but over time, it’s going to add up and I’ll probably end up exceeding whatever the default maxlength for a multiline textbox is. The only thing I can think of to do to prevent this from happening is to hook into the OnKeyPress event handler and check the length of the textbox before I add something to it and, when necessary, to remove the older text to make room for the newer text. But this seems like it would definitely have an impact on performance. Someone please tell me that there is a better way to do this?
A Winforms TextBox has a maximum length of 2GB.
You’ll have to worry about usability long before you worry about memory issues – if the log is too long, your users are not going to be able to use it effectively.