I have an application that does a large amount of number crunching on an array of numbers. I have it set to every 100,000 operations to display the status of those numbers.
+1 for Hans.
Also, you're using StringBuilder. Awesome.
However, you're concatenating FOUR strings for every item in arraystatus
(which could be 100k for all I know) for each time your UI is updated, making StringBuilder pretty much pointless.
Try
s.Append(i.ToString());
s.Append(":\t");
s.Append(item.ToString());
s.Append(i % 8 == 0 ? "\n" : "\t"));
or, even better, try converting this to a single call of AppendFormat
.
From the documentation of the TextBoxBase.UndoLimit property:
The number of actions stored in the undo queue. The default is –1, which means the undo queue is limited to the memory that is available.
You found that limit. Set it to a reasonably small value.
It otherwise doesn't normally make a lot of sense to display logging information in a TextBox. It is really meant to allow the user to enter text. Perhaps TextBlock is a better choice.
UPDATE: in .NET 4.5, the default of -1 was changed to 100 to avoid this kind of runaway memory usage.