I've written code that uses a thread to read a 70K line CSV file one line at
a time, however, after about 9 to 10 thousand lines into the file I get a
StackOverflowEx ception while the thread tries to update a counter.
I'm sure I'm doing this correctly but if anyone can tell me different I'd
appreciate it.
ssStrip is a StatusStrip on the main form.
Private WithEvents m_tHistorical As BackgroundWorke r = New BackgroundWorke r()
Private Sub cmdRun_Click(By Val sender As System.Object, ByVal e As
System.EventArg s) Handles cmdRun.Click
Me.ssStrip.Item s(1).Visible = True
Me.ssStrip.Item s(2).Visible = True
m_tHistorical.R unWorkerAsync(N ew
StreamReader("S SG_Historical-29-03-2007.csv", False))
End Sub
Private Sub m_tHistorical_D oWork(ByVal sender As Object, ByVal e As
System.Componen tModel.DoWorkEv entArgs) Handles m_tHistorical.D oWork
e.Result = ReadHistoricalC SV(CType(sender , BackgroundWorke r), e)
End Sub
Private Function ReadHistoricalC SV(ByVal W As BackgroundWorke r, ByVal e
As DoWorkEventArgs ) As Boolean
Dim S As StreamReader = CType(e.Argumen t(), StreamReader), Result As
Boolean = False
Static Rows As Integer = 0
If (W.Cancellation Pending()) Then
e.Cancel = True
Else
Result = S.EndOfStream()
If (Result) Then
S.Close()
Else
S.ReadLine()
Rows += 1
UpdateHCSVRows( Rows) ' <-- This is the line with the
StackOverFlow
Result = ReadHistoricalC SV(W, e)
End If
End If
Return Result
End Function
Private Sub UpdateHCSVRows( ByVal R As Integer)
If (Me.ssStrip.Inv okeRequired()) Then
Me.Invoke(New CSVHRowsCallbac k(AddressOf UpdateHCSVRows) , New
Object() {R})
Else
Me.ssStrip.Item s(1).Text = FormatNumber(R, 0,
TriState.UseDef ault, TriState.UseDef ault, TriState.True)
End If
End Sub
--
Regards,
Bubba
a time, however, after about 9 to 10 thousand lines into the file I get a
StackOverflowEx ception while the thread tries to update a counter.
I'm sure I'm doing this correctly but if anyone can tell me different I'd
appreciate it.
ssStrip is a StatusStrip on the main form.
Private WithEvents m_tHistorical As BackgroundWorke r = New BackgroundWorke r()
Private Sub cmdRun_Click(By Val sender As System.Object, ByVal e As
System.EventArg s) Handles cmdRun.Click
Me.ssStrip.Item s(1).Visible = True
Me.ssStrip.Item s(2).Visible = True
m_tHistorical.R unWorkerAsync(N ew
StreamReader("S SG_Historical-29-03-2007.csv", False))
End Sub
Private Sub m_tHistorical_D oWork(ByVal sender As Object, ByVal e As
System.Componen tModel.DoWorkEv entArgs) Handles m_tHistorical.D oWork
e.Result = ReadHistoricalC SV(CType(sender , BackgroundWorke r), e)
End Sub
Private Function ReadHistoricalC SV(ByVal W As BackgroundWorke r, ByVal e
As DoWorkEventArgs ) As Boolean
Dim S As StreamReader = CType(e.Argumen t(), StreamReader), Result As
Boolean = False
Static Rows As Integer = 0
If (W.Cancellation Pending()) Then
e.Cancel = True
Else
Result = S.EndOfStream()
If (Result) Then
S.Close()
Else
S.ReadLine()
Rows += 1
UpdateHCSVRows( Rows) ' <-- This is the line with the
StackOverFlow
Result = ReadHistoricalC SV(W, e)
End If
End If
Return Result
End Function
Private Sub UpdateHCSVRows( ByVal R As Integer)
If (Me.ssStrip.Inv okeRequired()) Then
Me.Invoke(New CSVHRowsCallbac k(AddressOf UpdateHCSVRows) , New
Object() {R})
Else
Me.ssStrip.Item s(1).Text = FormatNumber(R, 0,
TriState.UseDef ault, TriState.UseDef ault, TriState.True)
End If
End Sub
--
Regards,
Bubba
Comment