Question

I'm having troubles building a searchbox with reactive extensions. My goal is to get the latest text available every X milliseconds, do my search and post results back on a UI grid (winforms). But i'm stuck with first step.

I can see by logging that multiple events are fired in 5000 milliseconds using Rx Sample, not only one! I expected 1 time every 5000 ms max.

My code is really simple and i strongly believed it worked:

        EventLoopScheduler scheduler = new EventLoopScheduler(ts => new Thread(ts));   
        Observable.FromEventPattern<EventArgs>(this.textBox1, "TextChanged")
        .Sample(new TimeSpan(5000), scheduler).ObserveOn(this).Subscribe
        (
            args =>
            {
                string text = ((TextBox)args.Sender).Text;
                Console.WriteLine("Sample fired. Text: {0}", text);
            }
        );

I'm wiring up everything in the constructor of a Form. Am i messing up with scheduler? Thank you.

Was it helpful?

Solution

Instead of new TimeSpan(5000) which is 5000 ticks and not very long at all, use TimeSpan.FromSeconds(5).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top