Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6615083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:25:07+00:00 2026-05-25T20:25:07+00:00

I have a search function in my program that uses a background worker in

  • 0

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.

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) ' <-- 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

And I get this error

An unhandled exception of type 'System.StackOverflowException' occurred in System.Windows.Forms.dll

I’ve tried this, but it doesn’t make a difference

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

Edit:
Oh, and if I just step through the code, it doesn’t have any problems.

Edit 2:
Here is the backgroundworker DoWork event:

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 = " & CustomerID & " OR CustomerName Like '" & doSearchText & "%'"
    If Not doSearchText.Contains(" ") Then
        sWhere &= " OR FirstName Like '" & doSearchText & "%' OR LastName Like '" & doSearchText & "%'"
    Else
        Dim str() As String = doSearchText.Split(" ")
        sWhere &= " OR (FirstName Like '" & str(0) & "%' AND LastName Like '" & str(1) & "%')"
    End If

    Dim i As Integer = 0
    Dim tmpCustomer As CustomerItem

    With rSelect
        .Open(sSql & sWhere & " 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" & .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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:25:07+00:00Added an answer on May 25, 2026 at 8:25 pm

    I think the problem is likely this line:

    Application.DoEvents()
    

    If your BackgroundWorker is queueing up ProgressChanged events fast enough, each call to Application.DoEvents() will work through the message queue, come to a ProgressChanged event, update the progress, call Application.DoEvents(), work through the message queue, come to a ProgressChanged event, etc.. essentually causing a recursive behavior in your code.

    Try removing that call and see if the problem goes away.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that uses Pattern#compile and a Matcher to search a list
I have the following program that uses ptr_fun with a lambda function. #include <iostream>
I have a search program that will be looking at a database from a
if i have a search function for my site and i want the user's
I have an active directory search function: Function GetAdInfo(ByVal ADDN As String, ByVal ADCommonName
I have a problem using the Java search function in Eclipse on a particular
How can i have slide downeffect? The effect will be similar with search function
hai I have a magento web site. In this the search function compare with
I have the following code in my .Zshrc function google; { $VIEW http://www.google.com/search?q='url-encode ${(j:
I've got a function that takes a list of CRuntimeClass pointers in order to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.