G
Guest
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
StackOverflowException 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 BackgroundWorker = New BackgroundWorker()
Private Sub cmdRun_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdRun.Click
Me.ssStrip.Items(1).Visible = True
Me.ssStrip.Items(2).Visible = True
m_tHistorical.RunWorkerAsync(New
StreamReader("SSG_Historical-29-03-2007.csv", False))
End Sub
Private Sub m_tHistorical_DoWork(ByVal sender As Object, ByVal e As
System.ComponentModel.DoWorkEventArgs) Handles m_tHistorical.DoWork
e.Result = ReadHistoricalCSV(CType(sender, BackgroundWorker), e)
End Sub
Private Function ReadHistoricalCSV(ByVal W As BackgroundWorker, ByVal e
As DoWorkEventArgs) As Boolean
Dim S As StreamReader = CType(e.Argument(), StreamReader), Result As
Boolean = False
Static Rows As Integer = 0
If (W.CancellationPending()) 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 = ReadHistoricalCSV(W, e)
End If
End If
Return Result
End Function
Private Sub UpdateHCSVRows(ByVal R As Integer)
If (Me.ssStrip.InvokeRequired()) Then
Me.Invoke(New CSVHRowsCallback(AddressOf UpdateHCSVRows), New
Object() {R})
Else
Me.ssStrip.Items(1).Text = FormatNumber(R, 0,
TriState.UseDefault, TriState.UseDefault, TriState.True)
End If
End Sub
a time, however, after about 9 to 10 thousand lines into the file I get a
StackOverflowException 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 BackgroundWorker = New BackgroundWorker()
Private Sub cmdRun_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdRun.Click
Me.ssStrip.Items(1).Visible = True
Me.ssStrip.Items(2).Visible = True
m_tHistorical.RunWorkerAsync(New
StreamReader("SSG_Historical-29-03-2007.csv", False))
End Sub
Private Sub m_tHistorical_DoWork(ByVal sender As Object, ByVal e As
System.ComponentModel.DoWorkEventArgs) Handles m_tHistorical.DoWork
e.Result = ReadHistoricalCSV(CType(sender, BackgroundWorker), e)
End Sub
Private Function ReadHistoricalCSV(ByVal W As BackgroundWorker, ByVal e
As DoWorkEventArgs) As Boolean
Dim S As StreamReader = CType(e.Argument(), StreamReader), Result As
Boolean = False
Static Rows As Integer = 0
If (W.CancellationPending()) 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 = ReadHistoricalCSV(W, e)
End If
End If
Return Result
End Function
Private Sub UpdateHCSVRows(ByVal R As Integer)
If (Me.ssStrip.InvokeRequired()) Then
Me.Invoke(New CSVHRowsCallback(AddressOf UpdateHCSVRows), New
Object() {R})
Else
Me.ssStrip.Items(1).Text = FormatNumber(R, 0,
TriState.UseDefault, TriState.UseDefault, TriState.True)
End If
End Sub