cogumel0
cogumel0

Reputation: 2681

Wait for "last" event to fire

I need to block execution of my code until a user enters something into a TextBox.

However, in this particular case, I actually need to wait "until the user has finished typing". I.e., I don't want to just wait for the first time that the TextChanged event fires, I want to wait until at least 500ms have passed since the last time it fired before continuing the execution of my method.

Currently I have something that uses timers where every time the TextChanged event fires the timer is restarted and when the timer's Tick event fires it means that the user "has finished typing".

There are three main problems with this approach right now though:

How can I accomplish this?

Upvotes: 0

Views: 380

Answers (1)

Rune Grimstad
Rune Grimstad

Reputation: 36340

This is very easy to do using ReactiveUI. Look at the example on the main page. It does more or less exactly what you are after.

It is based on Reactive Extensions (RX) for .Net and is written to make things like these easy. If using ReactiveUI is not an option then I suggest you look at RX and how ReactiveUI implements this.

Upvotes: 2

Related Questions