Re: Fastest way to append text to a TextBox
- From: "jeff" <jhersey at allnorth dottt com>
- Date: Wed, 2 Apr 2008 10:24:56 -0800
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.
.
- References:
- Fastest way to append text to a TextBox
- From: Phill W.
- Fastest way to append text to a TextBox
- Prev by Date: Codedom and resources files
- Next by Date: Re: VB sql statement
- Previous by thread: RE: Fastest way to append text to a TextBox
- Next by thread: Re: Fastest way to append text to a TextBox
- Index(es):
Relevant Pages
|