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 3243638
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:27:25+00:00 2026-05-17T18:27:25+00:00

In a Windows Form, I have a search box that fires an event to

  • 0

In a Windows Form, I have a search box that fires an event to search a remote database and display some results. The query is pretty fast, usually just a fraction of a second, but in case the delay is noticeable there is a progress bar and label in the form’s status bar. When the user clicks “Search” the status label should appear and the progress bar show some progress. Then when the result comes back the label should disappear and the progress bar should be full. Pretty basic response.

The problem is, I can’t get those actions to happen in that order. Using the code below, I click “Search”, nothing happens until the results are displayed, and then the progress bar fills up from 0 to 100. The label never appears. I even threw in a sleep command immediately after the event to be sure I wasn’t just missing it, but it’s as if the first 2 statements are not being executed. What am I doing wrong here?

 private void searchButton_Click(object sender, EventArgs e)
    {
        toolStripStatusLabel1.Visible = true;
        toolStripProgressBar1.Value = 20;
        m_changeRequestedEvents.Fire<String>("SearchTerm", searchTextBox.Text);
        toolStripProgressBar1.Value = 100;
        toolStripStatusLabel1.Visible = false;
    }
  • 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-17T18:27:26+00:00Added an answer on May 17, 2026 at 6:27 pm

    The code provided changes the UI attributes, but the thread can’t repaint the UI until after searchButton_Click returns. So the changes made before the event are never applied, because they’re overridden by the changes made after, which are then applied when the method returns.

    Instead, update the UI attributes before firing the event:

    searchButton.Enabled = false;
    toolStripProgressBar1.Value = 0;
    toolStripStatusLabel1.Visible = true;
    m_changeRequestedEvents.Fire<String>("SearchTerm", searchTextBox.Text);
    

    and from the event handler, run the query in a separate thread (BackgroundWorker), so that the UI can update in the meantime:

    private void View_OnSearchTermChangeRequest(Object sender, PropertyChangeRequestEventArgs<String> args)
    {
        m_search_bgw = new BackgroundWorker();
        ...
        m_DBHandler.current_worker = m_search_bgw;
        m_search_bgw.RunWorkerAsync(args.RequestedValue);
    }
    

    then update the UI again in the method that is called when the BackgroundWorker thread completes:

    void UpdateView(DataView projects)
    {
        dataGridView1.DataSource = projects;
        ...
        toolStripProgressBar1.Value = 100;
        toolStripStatusLabel1.Visible = false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one windows form file that each time I open it in Visual
i have a windows form that contains a bunch of textboxes. I need a
I have a windows form on the main thread and another thread that does
I want to implement a search box in a window form. In that window
I'm making a Windows Form project that will search for files in the specified
I have a report that is used by a windows service and a form
I have an input box in html form and onKeyPress of that box I
On a Windows form I have an unbound datagridview with 1 user-editable column. A
I am using a windows form and within the form i have a user
Windows form application(.Net 3.5) I have a textbox and a button on the form.

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.