title: Stackoverflow error in BackgroundWorker ProgressChanged
body: <p>I have a search function in my program that uses a background worker in order to get the results. The Progress changed event is used to update the listview with the new item.</p>
  
  <pre><code>Private Sub SearchWorker_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles SearchWorker.ProgressChanged
      Dim itmX As ListViewItem
      Dim tmpCustomer As CustomerItem
  
      If e.UserState.ToString = "New" Then
          lstResults.Items.Clear()
      Else
          Try
              tmpCustomer = e.UserState
              itmX = lstResults.Items.Add(tmpCustomer.CustomerName) ' &lt;-- Error here
              itmX.Tag = tmpCustomer.CustomerID
              itmX.Name = tmpCustomer.CustomerID
              itmX.SubItems.Add(tmpCustomer.City)
              itmX.SubItems.Add(tmpCustomer.State)
              itmX.SubItems.Add(tmpCustomer.Zip)
          Catch ex As Exception
              MsgBox(ex.Message)
          End Try
      End If
  
      progBar.Value = e.ProgressPercentage
  
      Application.DoEvents()
  End Sub
  </code></pre>
  
  <p>And I get this error</p>
  
  <pre><code>An unhandled exception of type 'System.StackOverflowException' occurred in System.Windows.Forms.dll
  </code></pre>
  
  <p>I've tried this, but it doesn't make a difference</p>
  
  <pre><code>Private Sub SearchWorker_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles SearchWorker.ProgressChanged
  
      If e.UserState.ToString = "New" Then
          lstResults.Items.Clear()
      Else
          Try
              itmX = lstResults.Items.Add("Test")
          Catch ex As Exception
              MsgBox(ex.Message)
          End Try
      End If
  
      progBar.Value = e.ProgressPercentage
  
      Application.DoEvents()
  End Sub
  </code></pre>
  
  <p>Edit:
  Oh, and if I just step through the code, it doesn't have any problems.</p>
  
  <p>Edit 2:<br>
  Here is the backgroundworker DoWork event:</p>
  
  <pre><code>Sub doSearch(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles SearchWorker.DoWork
      canceled = False
      If curSearch = doSearchText Then
          canceled = True
          Exit Sub
      End If
      curSearch = doSearchText
  
      SearchWorker.ReportProgress(0, "New")
      Dim rSelect As New ADODB.Recordset
      Dim CustomerID As Integer = MakeNumeric(doSearchText)
      Dim sSql As String = "SELECT DISTINCT CustomerID, CustomerName, City, State, Zip FROM qrySearchFieldsQuick WHERE "
      Dim sWhere As String = "CustomerID = " &amp; CustomerID &amp; " OR CustomerName Like '" &amp; doSearchText &amp; "%'"
      If Not doSearchText.Contains(" ") Then
          sWhere &amp;= " OR FirstName Like '" &amp; doSearchText &amp; "%' OR LastName Like '" &amp; doSearchText &amp; "%'"
      Else
          Dim str() As String = doSearchText.Split(" ")
          sWhere &amp;= " OR (FirstName Like '" &amp; str(0) &amp; "%' AND LastName Like '" &amp; str(1) &amp; "%')"
      End If
  
      Dim i As Integer = 0
      Dim tmpCustomer As CustomerItem
  
      With rSelect
          .Open(sSql &amp; sWhere &amp; " ORDER BY CustomerName", MyCn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockReadOnly)
          Do While Not .EOF
              If SearchWorker.CancellationPending Then
                  canceled = True
                  Exit Do
              End If
  
              Do While IsDBNull(.Fields("CustomerID").Value)
                  .MoveNext()
              Loop
  
              tmpCustomer.CustomerID = "c" &amp; .Fields("CustomerID").Value
              tmpCustomer.CustomerName = NZ(.Fields("CustomerName").Value, "").ToString.Trim
              tmpCustomer.City = Trim(NZ(.Fields("City").Value, ""))
              tmpCustomer.State = Replace(Trim(NZ(.Fields("State").Value, "")), ",", "")
              tmpCustomer.Zip = Trim(NZ(.Fields("Zip").Value, ""))
  
              SearchWorker.ReportProgress((i / .RecordCount) * 100, tmpCustomer)
              i += 1
              Application.DoEvents()
  aMoveNext:
  
              .MoveNext()
          Loop
          .Close()
      End With
  End Sub
  </code></pre>