Hi guys, I am trying to implement a BGW and want to report progress to a progress bar for my TextFieldParser program, sometimes if your opening very large files it takes a while and I would like the user to be able to see the progress and have some interaction so they know the program is still running
I am a little hung up on what to in the reportprogress
I have:
worker.ReportProgress(0, myReader.ReadFields())
and its not doing anything, I didnt expect it too since ReadFields is an array
any suggestions or help would be appreciated here is the code for my TextFieldParser
parser Code:
Private Sub BackgroundWorker1_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork Dim worker As System.ComponentModel.BackgroundWorker = DirectCast(sender, System.ComponentModel.BackgroundWorker) Dim safeFileName As String = Me.OpenFileDialog1.FileName Using myReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(safeFileName) myReader.SetDelimiters(vbTab) Dim currentRow As String() currentRow = myReader.ReadFields() Dim colNameList As New List(Of String) Dim colName As String = String.Empty For i As Integer = 0 To currentRow.GetUpperBound(0) colName = currentRow(i) Dim suffix As Integer = 1 While colNameList.Contains(colName) colName = currentRow(i) & suffix.ToString suffix += 1 End While colNameList.Add(colName) Next For Each currentField As String In colNameList table.Columns.Add(currentField, GetType(System.String)) Next While Not myReader.EndOfData Try currentRow = myReader.ReadFields() table.Rows.Add(currentRow) worker.ReportProgress(0, myReader.ReadFields()) Catch ex As Exception End Try End While End Using If table.Columns.Contains("Column1") Then table.Columns.Remove("Column1") End If dtAll = table End Sub




Reply With Quote