【问题标题】:Searchbox with Reactive Extensions and textbox Textchanged event带有响应式扩展和文本框 Textchanged 事件的搜索框
【发布时间】: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


【解决方案1】:

使用TimeSpan.FromSeconds(5),而不是new TimeSpan(5000),它有5000 个滴答而且一点也不长。

【讨论】:

    猜你喜欢
    • 2014-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多