Re: Fastest way to append text to a TextBox



let me ask this....

10,000 lines in 3 seconds ... that is 3,333 per second ... and you want this
real time ... why? I have yet to see a speed reader achive this type of
performance.

Write logical blocks or write to text control every second.

When you update a 'control' there is much more going on than simple string
concatinaction -> the visual part of the process must be considered ... and
so on.


Jeff.

"Phill W." <p-.-a-.-w-a-r-d-@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:fsvvvs$nai$1@xxxxxxxxxxxxxxxxxxxx
VB.Net 2005 SP1
Windows Forms Application

What's the fastest way to append text to a [Rich]TextBox?

I have an application that monitors data written to text [log] files. It
needs to scan some fairly hefty files (typically ~15MB) and scanning the
file pulling out the rows I want (typically ~10,000 of them) takes
/comfortably/ under three seconds. In normal usage, this application will
"follow" the end of these files as they are written to, so it needs to be
able to scan [the end of] the file and update the screen in "real time".

However if, as I find them, I take each of these lines and append them to
the end of a TextBox on a Form, the process slows to a crawl, red-lines my
CPU and, even if I limit the TextBox to just 30KB of text, it takes over
90 seconds to complete.
(This will eventually be a RichTextBox because the output lines will need
to be colour-coded as well, but I'm trying to start simple).


So, how can I get these lines into my TextBox /faster/?

Or, rather, why is updating the control /so/ slow, compared to hacking
strings around in memory?


OK, OK, normally, even /I'd/ be the first to say

"who /needs/ to see 10,000 lines of data?"

but, I can think of at least three of my users who will want [the
opportunity] to see every single one of them.

I have to say I was stunned at how fast VB.Net crunched its way through
the data, but if getting that data up onto the screen is going to be
/this/ slow, it's hardly worthwhile doing the "upgrade".

My "appending" code:

Private Sub AppendText(ByVal sText As String)
With Me.TextBox1
Dim iLen As Integer = .Text.Length + sText.Length

If (iLen >= (30000 * 1.1)) Then
Dim iTrimmer As Integer = iLen - 30000
Dim iPos As Integer = .Text.IndexOf(vbCrLf, iTrimmer)
.SelectionStart = 0
.SelectionLength = iPos + 1
.SelectedText = String.Empty
End If

.SelectionStart = .Text.Length
.SelectedText = sText & vbCrLf

.SelectionStart = .Text.Length

End With
End Sub

(Without the trimming bit, it's even more, /unbelievably/ slow; I got fed
up waiting after five minutes.)

Any suggestions?

TIA,
Phill W.


.



Relevant Pages

  • Re: Parsing / " characters
    ... have the rest of the code to append the ... - JCL inserts that string at the start of every program, ... >>the code associated with that program - in exact order, ... >>Dim db As Database, tdf As TableDef ...
    (microsoft.public.access.externaldata)
  • RE: Array Type Mismatch
    ... Function TextBoxGetLines(txtDone As TextBox, Optional KeepHardLineBreaks As ... Dim resultAs String ...
    (microsoft.public.access.formscoding)
  • Re: Parsing / " characters
    ... create a new record in table TTT containing the string ... >I can append ALL the records from the ... >Dim db As Database, tdf As TableDef ... >> Dim lngFN as Long ...
    (microsoft.public.access.externaldata)
  • RE: Array Type Mismatch
    ... I am getting "" for all the elements of my array. ... Function TextBoxGetLines(txtDone As TextBox, Optional KeepHardLineBreaks As ... Dim resultAs String ...
    (microsoft.public.access.formscoding)
  • Re: File Append Row by Cell value
    ... Dim vFile As String ... Dim vFound As Boolean ... Can you append rows and can they be comma seperated? ...
    (microsoft.public.excel.programming)