【发布时间】:2014-01-10 11:12:40
【问题描述】:
我在构建带有响应式扩展的搜索框时遇到了麻烦。 我的目标是每 X 毫秒获取一次可用的最新文本,进行搜索并将结果发布回 UI 网格(winforms)。但我坚持第一步。
我可以看到,使用 Rx Sample 在 5000 毫秒内触发了多个事件,而不仅仅是一个!我预计最多每 5000 毫秒 1 次。
我的代码非常简单,我坚信它有效:
EventLoopScheduler scheduler = new EventLoopScheduler(ts => new Thread(ts));
Observable.FromEventPattern<EventArgs>(this.textBox1, "TextChanged")
.Sample(new TimeSpan(5000), scheduler).ObserveOn(this).Subscribe
(
args =>
{
string text = ((TextBox)args.Sender).Text;
Console.WriteLine("Sample fired. Text: {0}", text);
}
);
我在表单的构造函数中连接所有内容。 我搞砸了调度程序吗? 谢谢。
【问题讨论】:
-
您是否尝试删除
scheduler参数和.ObserveOn(this)运算符? -
无法删除它们,需要响应式 UI。
标签: winforms system.reactive observable search-box