ale
ale

Reputation: 3

RichTextBox takes too long to print results

In WinForms, I have a list with more than 10000 rows.
I have to print each row in a RichTextBox control, but the program freezes, and takes something like 10 minutes. In order to create the list, the program takes 3 seconds.

My problem is: how can I print the result without waiting so much?

Here's the code:

for(int i=0; i < 1000; i++) {
  //(...) add a row
}

foreach (string item in list)
{
    richTextBox1.Text += item + "\r\n";
}

Upvotes: 0

Views: 161

Answers (1)

G&#225;bor Bakos
G&#225;bor Bakos

Reputation: 9100

Use StringBuilder and assign its result to the richTextBox1.Text:

  var sb = new StringBuilder();
  foreach (string item in list)
  {
     sb.Append(item + "\r\n");
  }
  richTextBox1.Text += sb.ToString();

Upvotes: 3

Related Questions