Newbie help: Application freezes

  • Thread starter Thread starter steve
  • Start date Start date
S

steve

Hello,

I have been working on this piece of code that's supposed to read from a
file - transform - preview and finally save the transformed data.

I can read the file and with RichtextBox.LoadFile( ) i can display it on
the first box.

Then, in a for loop i read line by line , extract the information and (the
idea is) to put the transformed data in another RichText Box so that the
user can decide wether to save them in a file or not.

However i noticed that with files of around 1Meg and more , the process
slows down and freezes ! There is no exception raised, or i don't see it in
my Try block ... , the MaxSize for the textbox cannot be increased futher,
and I have tried everything except calling the CG explicitly but i don't see
the point in this piece of code.

Please help. I have spend hours on this and can't figure out what could be
wrong.

TIA



*******************************************************************

Try 'Put writing loop in a try-catch block

'*********************************************

'Main Loop over all lines of Global ArrayList

'------------- STEP 1 ------------------------

' -- READ data from global array into structure

For Each LineStr In globalArrayListIN

'Check each line length IF different than 233

If (LineStr.Length = 234 Or LineStr.Length = 233) Then

'increase progress bar

pbrTransform.Value += 1

'extract Station ID , year , month , element code

tempLine.stationID = LineStr.Substring(0, 7)

tempLine.year = LineStr.Substring(7, 4)

tempLine.month = LineStr.Substring(11, 2)

tempLine.element = LineStr.Substring(13, 3)

'Loop in order to get data for the 31 days of the month on the same line

For i As Integer = 0 To 30

tempLine.value(i) = LineStr.Substring(16 + (i * 7), 7)

Next

'------------- STEP 2 ------------------------

'-- ADD lines to the Transformed preview pane

rtbTransformed.AppendText(tempLine.stationID)

rtbTransformed.AppendText(delimiter + tempLine.year)

rtbTransformed.AppendText(delimiter + tempLine.month)

rtbTransformed.AppendText(delimiter + tempLine.element)

For i As Integer = 0 To 3

rtbTransformed.AppendText(delimiter + tempLine.value(i))

Next

rtbTransformed.AppendText(vbCrLf)

'IF file format is NOT correct, advise user and exit loop

Else

MsgBox("Le fichier n'as pas le propre format de 234 characters par ligne." +
vbCrLf + "SVP essayer de nouveau.")

Exit For

End If

Next

Catch ex As Exception

MsgBox(ex.ToString)

Finally

pbrTransform.Value = 0 'clear progress bar

End Try
 
The code you have only loop up to 30 times. 1 MB file??? Anyway it might not
be freezes rather infinity loop. Have a check.

chanmm
 
No! it loops as many lines as there are in globalArrayListIN.

I dont think there is an infinite loop anywhere. Depending on the size of
the file , it is either fast, slow or .... freezing.

Actually if i take off the part that displays the result in the TextBox and
only do the calculations, the progress bar is "flying" ! very fast. So, it
has something to do with writing to the textbox...... !!!????

Very weird!!! as i said it raises NO exceptions.
 
Havent tried anything yet because it looks complicated, but i think this
*IS* my problem too.
i spent 3 days on a stupid .net bug !??!

I really *appreciate* you pinpointing this bug Cor.
thanx a million

PS: If it has already happened to you, do you have a fast way / advise to
fix this OR get around it?
 
PS: If it has already happened to you, do you have a fast way / advise to
fix this OR get around it?

I have not experienced the problem and I'm sure Cor has a good solution but
I thought I'd offer a suggestion.

You might try using a StringBuilder and append all your text to that and
then append the stringbuilder to the rtb all in one shot. I'm not sure if
that will circumvent the bug but it's worth a shot.

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 

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

Back
Top