I have a TextBox
which acts like a search field
. If a user types in a character, the TextChanged event
is triggered immediately (after every character input!) and a long database operation is triggered.
What I want to do is, wrap that event
into an observable
, combine it with a delay
that lasts until there are no changes for 500ms and then triggers only for 1 time.
This is what I have so far, but I don't know how or what logic I have to add that it only pushes the last input.
Observable.FromEventPattern<TextChangedEventHandler, TextChangedEventArgs>(
h => SearchField.TextChanged += h,
h => SearchField.TextChanged -= h)
.Delay(TimeSpan.FromMilliseconds(500))
.Subscribe(args =>
{
// long database operation
});
Found the answer: