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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:29:50+00:00 2026-05-31T13:29:50+00:00

I am implementing a autocomplete control. Every time the user types a new character

  • 0

I am implementing a autocomplete control. Every time the user types a new character into a input, a query will fire. In order to test I have created a large database where the average query takes about 5 seconds to execute.

Because the query takes 5 seconds to execute I execute the query on a new thread:

   // execute the following lamda expression when user enters characters to textbox
   textBox1.TextChanged +=(x,eventArgs)=>{

            // execute query on separate thread
            new Thread(new ThreadStart(() =>
            {
                ObservableCollection = MyEntities.Entities.Products.Where(p => p.Name.Contains(inputText));
            })).Start();
    };

ObservableCollection and inputText are properties binded to my textbox and list.

The problem is that if the user types two characters my program will be running two threads at the same time. How can I abort the query?


Things that I am thinking about:

Create a bool variable IsQueryRuning and set it equal to true quen query starts and equal to false when thread ends. If a new query will be executed and IsQueryRuning = true then I can set ObservableCollection =null and cause an exeption. I will then resove it with a try catch block. I think that technique is not the best approach..


Edit:

Setting property Collection=null sometimes causes an exception and some other times it does not…

  • 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-31T13:29:50+00:00Added an answer on May 31, 2026 at 1:29 pm

    I would suggest a different approach, if that is possible to change for you.

    Instead of querying on each keystroke of the user, I would only do a query after, for example, 3 characters. Keep the result in some collection in memory.

    After that, only do the next queries on the in-memory collection. That spares you any following database accesses that are always much slower and ou should get a considerable performance gain.

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

Sidebar

Related Questions

I'm interested in implementing autocomplete in Python. For example, as the user types in
Implementing Equals() for reference types is harder than it seems. My current canonical implementation
Now, I'm developing a command-line application somewhat like bash. For implementing the autocomplete functionality,
I am implementing a jquery autocomplete on a search form and am getting the
I am implementing jQuery-ui autocomplete function in my website. In IE6, the autocomplete box
Implementing the very first scala example I ran into some problems probably tipical for
Implementing a custom VM and I've come to use registers (these will store pointers
I'm implementing a AJAX autocomplete/autosuggest feature, and not only do I want to do
I am implementing YUI autocomplete in my project. I have created a web service
I have a UITextField where I am implementing autocomplete in a UIPopoverController . I

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.