Q:

Autocomplete: Asynchronous population with WCF using threads

I have an "autocomplete" textbox that will invoke a WCF method each time a key is pressed.
The WCF server, in turn, will run an SQL query, return the first 15 results and send them.
However, this results in a noticeable latency when typing in the box.
What I'm about to do instead is this:

Create a new thread when a text_changed event is fired, make that thread wait 1000ms using Stopwatch.ElapsedMilliseconds. During this waiting time, the thread can be stopped permanently.
If it was not stopped, the thread will send the request to the server (and repopulate the auto complete box).
As soon as a new "text_changed" event is fired, I will stop the current thread and start a new one.

Is there a better approach or is this the way to go?

A:

Another approach is to use the Rx (Reactive Extensions) framework to encapsulate automplete with some very interesting characteristics. 
With Rx you get ability to compose (multiple event sources), throttle the user input so that you don't overwhelm the source, and on top of that you can ignore the old result if user typed more in the search box (TakeUntil).
More info:
Rx: Curing your asynchronous programming blues
Curing the asynchronous blues with the Reactive Extensions for .NET
Example:
SO: RX AutoCompleteBox
RxProperty = Observable.FromEvent<TextChangedEventHandler, TextChangedEventArgs>(
        h => new TextChangedEventHandler(h),
        h => AssociatedObject.TextChanged += h,
        h => AssociatedObject.TextChanged -= h)

        .Select(t => ((TextBox)t.Sender).Text)

        .Throttle(TimeSpan.FromMilliseconds(400))

        .SubscribeOnDispatcher()
        .Take(10)
        .TakeUntil(AssociatedObject.TextChanged );

Instead of FromEvent you can use FromAsync and use proxy Beginxxx Endxxx methods.

