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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:41:20+00:00 2026-05-27T19:41:20+00:00

I have a WPF application with the autocomplete box via the toolkit (VS 2008).

  • 0

I have a WPF application with the autocomplete box via the toolkit (VS 2008). I have a potential population of about 2000 records and I have tried to improve performance with a combination of the populating event procedure. I am getting inconsistent results. The filter seems to be OK but I can run the app once and result X will be there but result Y wont. Running it again can make result Y be there and not X, subsequent times both X and Y will be there, etc, etc. This is my first time using the autocomplete box so I’m sure it must be something in my code that I’m forgetting. If I check my result set just prior to the Itemsource binding, the desired results are there, but they are not made visible to the user – the drop-down autocomplete back does not show. Maybe I need an event override???

The XAML

<input:AutoCompleteBox                         
Name="autGlobal"
FilterMode="Contains"
Style="{DynamicResource MiniSearchAutoBoxWPF}"
IsTextCompletionEnabled="false" 
Margin="5, 0, 5, 0" 
HorizontalAlignment="Center"
KeyUp="autGlobal_KeyUp"
Text="Search Term" 
GotFocus="autGlobal_GotFocus"
ValueMemberPath="Item" 
Populating="AutoCompleteBox_Populating"
>

The Methods

 private void AutoCompleteBox_Populating(object sender, PopulatingEventArgs e)
            {
            e.Cancel = true;
            var b = new BackgroundWorker();
            currSearch = autGlobal.Text;
            b.DoWork += b_DoWork;
            b.RunWorkerCompleted += b_RunWorkerCompleted;
            b.RunWorkerAsync(autGlobal.Text);
        }

private void b_DoWork(object sender, DoWorkEventArgs e)
        {
            Results.Clear();
            int counter = 0;
            string search = e.Argument.ToString();
            search = search.ToUpper();
            foreach (GlobalSearchList person in myGlobalList)
            {
                if (person.Item.ToUpper().Contains(search))
                {
                    Results.Add(person);
                    counter++;

                    if (counter >= MAX_NUM_OF_RESULTS)
                    {                        
                        break;
                    }
                }
            }
        }

private void b_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {

            if (this.Dispatcher.Thread == System.Threading.Thread.CurrentThread)
            {
                //Set the source
                if (currSearch == autGlobal.Text)
                {
                    autGlobal.ItemsSource = Results;
                    autGlobal.PopulateComplete();
                }
            }
            else
            {
                this.Dispatcher.Invoke(new Action(() =>
                {
                    //Set the source
                    if (currSearch == autGlobal.Text)
                    {
                        autGlobal.ItemsSource = Results;
                        autGlobal.PopulateComplete();
                    }

                }));
            }            
        }
  • 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-27T19:41:21+00:00Added an answer on May 27, 2026 at 7:41 pm

    I’m not sure why you need the performance boost in the first place, you’re trying to calculate the elements that should be in the Autocomplete box in another thread and then assign them to the ItemsSource property of the Control. Something similar is what the AutoCompleteBox should do.

    I tryed bind the control to a list with 10000 strings and it works perfect, so your problem could be the size of the objects that you’re putting in the collection. One solution could be use just a string representation and then when you need the selected object you could find it based on it’s representation, assuming that is unique (if not you could put some sort of ID).

    One of the main problems with this approach is the thread sincronization, i will explain now why you get the extrange behavior where even when the filter is fine the items in the results are not right.

    The filter seems to be OK but I can run the app once and result X will
    be there but result Y wont. Running it again can make result Y be
    there and not X, subsequent times both X and Y will be there, etc,
    etc.

    Suppose that you write “ab” in the autocomplete box, this will start a new BackGroundWorker where this search is performed. Everything should be fine if you wait long enough. But if you change the search query before the first worker has finished, now all the results will be mixed. Take for example the following lines of code:

    // the user searchs for "ab"
    [Thread 1] Results.Clear();
    [Thread 1] Results.Add(Item[1]);
    [Thread 1] Results.Add(Item[2]);
    ...
    // the user changes the search term (to "abc" for example)
    [Thread 2] Results.Clear();
    [Thread 2] Results.Add(Item[3]);
    // but what would happen if the first BackGroundWorker hasn't finished yet,
    // this means that the first thread is still running
    [Thread 1] Results.Add(Item[5]); // this items doesn't match the second search
    [Thread 1] Results.Add(Item[6]); // criteria, but are added to the collection
    [Thread 2] Results.Add(Item[7]);
    // then you'll have two treads adding items to the Result collection
    [Thread 1] Results.Add(Item[2]);
    ...
    [Dispatcher Thread] autGlobal.ItemsSource = Results;
    [Dispatcher Thread] autGlobal.PopulateComplete();
    

    Hope this helps.

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

Sidebar

Related Questions

I have a WPF application and am using the WPF toolkit autocomplete box in
I have a WPF application in VS 2008 with some web service references. For
I have a WPF application that connects via a socket to a device and
I have WPF Application where I have One main form and other user controls
I have a WPF application that runs fine under XP as an administrator. When
I have a WPF application using Aero Glass. When using the application under a
We have a WPF Application that has a two flavors with a consistent UI
I have a WPF application, where when a user unchecks a checkbox, the application
I have a WPF application (.NET 3.0, VS2008) that displays data in a tab
i have a WPF Application with a LoginWindow to access,so i create a Splash

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.