Have a look at this:
vb.net Code:
  1. Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
  2.     '' move this to the start of your DoWork event procedure
  3.     Dim worker As System.ComponentModel.BackgroundWorker = DirectCast(sender, System.ComponentModel.BackgroundWorker)
  4.  
  5.     '' your other code
  6.  
  7.     Do While rdrfile.Peek <> -1
  8.         '' your other code
  9.  
  10.         If worker.CancellationPending Then Exit Do
  11.     Loop
  12.  
  13.     '' your other code
  14.  
  15.     For Each Str As String In FileLines
  16.         '' your other code
  17.  
  18.         If worker.CancellationPending Then Exit For
  19.     Next
  20.  
  21.     For Each filtereditem As String In Columns
  22.         '' your other code
  23.  
  24.         If worker.CancellationPending Then Exit For
  25.     Next
  26.  
  27.     '' your other code
  28.  
  29.     For Each item In Lines
  30.         '' your other code
  31.  
  32.         If worker.CancellationPending Then Exit For
  33.     Next
  34.  
  35.     '' your other code
  36.  
  37.  
  38.     '' just before End Sub
  39.     If worker.CancellationPending Then e.Cancel = True
  40. End Sub