【发布时间】:2011-01-14 12:31:42
【问题描述】:
我正在使用响应式扩展来验证文本框输入。 我正在尝试使用 .Throttle(TimeSpan.FromMilliseconds(500))。
但是当我添加 .Throttle() 方法时,在 .Subscribe() 方法中访问 UI 对象时会引发跨线程异常。
没有油门,它可以 100% 工作,为什么会坏掉?
我的代码:
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
});
谢谢 -奥利弗
【问题讨论】:
标签: silverlight exception system.reactive