I am using Reactive Extensions to verification of a textbox input.
I am trying to use the .Throttle(TimeSpan.FromMilliseconds(500)).
But when I add the .Throttle() method a cross thread exception is thrown when accessing a UI object in the .Subscribe() method.
It works 100% without the Throttle, why is it breaking?
My code:
var textChangedEvent = Observable.FromEvent<TextChangedEventArgs>(usernameTextbox, "TextChanged")
.Throttle(TimeSpan.FromMilliseconds(500))
textChangedEvent.Subscribe(changed =>
{
TextBox oUsernameTextBox = changed.Sender as TextBox;
//Accessing oUsernameTextBox throws Cross Thread Exception
});
Thanks
-Oliver
By default
Throttleuses theThreadpoolSchedulerso events will not arrive on the UI Thread. Since you need the events on the UI thread use:-This will put the events back on the UI Thread.