I have custom control inherited from Textbox.
I want to make delay in calling textchanged event.
Observable.FromEventPattern<TextChangedEventHandler, TextChangedEventArgs>(
handler => this.TextChanged += handler,
handler => this.TextChanged -= handler
).Throttle(TimeSpan.FromMilliseconds(600))
.Where(e =>
{
var control= e.Sender as TextBox;
return control!= null && !string.IsNullOrEmpty(control.Text);
})
.Subscribe(x => Control_TextChanged(x.Sender, x.EventArgs));
Problem is it is giving error saying, cannot access Text property as current thread does not have access.
Can someone please advice?
Thanks, Vishal
var control= e.Sender as TextBox;, but you're using Rx and lambdas sothisis still in scope. Your where-clause can be written as.Where(e => this != null && !string.IsNullOrEmpty(this.Text)).Control_TextChanged? That seems to be a backwards step. Just put the code in the.Subscriberather than inControl_TextChanged.Control_TextChangedis called from somewhere else in the code. Or if the function length is 1000 lines. Point being: I think the implicit function call is better