FIFO in a richTextBox

R

RonT

I have a richTextBox that is receiving lots of data over a serial port. The
problem is that the display of the text gets slower and slower as more and
more text is added (using .AppendText). Is there a way to limit the text
box to some fixed number of lines (or characters) of text such that the
first text in would automatically get dropped from the text box when the
limit is reached? I've tried using SelectionStart combined with
SelectionLength to select and cut the first line of text when the limit is
reached, but that gets the vertical scroll bar bouncing up and down as the
code bounces between adding new text and deleting old text. This results in
even worse performance of the text box.

Any thoughts or suggestions?

Thanks,

Ron
 
T

Tzim [MVS]

Did you try to round your SelectionStart/SelectionLength things with the
SupendsLayout and ResumeLayout calls ?
I'm interrested in the result because i'm writting an app where I may have
the same problem.

Tzim
[French MVS]
 
R

RonT

I just tried your suggestion and there was no change in behavior.

Thanks for the suggestion.

Any other ideas?

Ron

Tzim said:
Did you try to round your SelectionStart/SelectionLength things with the
SupendsLayout and ResumeLayout calls ?
I'm interrested in the result because i'm writting an app where I may have
the same problem.

Tzim
[French MVS]

RonT said:
I have a richTextBox that is receiving lots of data over a serial port.
The problem is that the display of the text gets slower and slower as more
and more text is added (using .AppendText). Is there a way to limit the
text box to some fixed number of lines (or characters) of text such that
the first text in would automatically get dropped from the text box when
the limit is reached? I've tried using SelectionStart combined with
SelectionLength to select and cut the first line of text when the limit is
reached, but that gets the vertical scroll bar bouncing up and down as the
code bounces between adding new text and deleting old text. This results
in even worse performance of the text box.

Any thoughts or suggestions?

Thanks,

Ron
 
G

Guest

If what you have is one big string (richtextbox.text in your case) and you
concatenate to it frequently, there is no hope in improving performance. The
reason is that each concatenation results in a string copy of the big string
plus some more work, and then there is an old big string that needs garbage
collection. You get the double whammy of longer concatenations and more
garbage collections.

What I do is use a VB Concat class that I wrote for this very purpose. The
gist of the class is an array of strings and an integer index into the array.
When you want to concatenate a string maintained therein, the class bumps
the index and stores the string in the array. Note that this is a cheap
operation of creating one more object reference to an existing string. When
the array becomes full, the Join() of the array is used to reinitialize the
array, and operations resume. At any point in time, Join() of the array is
the contents of the long string. I periodically (or when a processing step
has been made) update a richtextbox with the string being thus maintained in
the concat object. There may be a better implementation of this using string
builder, but I am satisfied with the performance of this concat class.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top