[英]Wait for “last” event to fire
I need to block execution of my code until a user enters something into a TextBox
. 我需要阻止代码执行,直到用户在
TextBox
输入内容为止。
However, in this particular case, I actually need to wait "until the user has finished typing". 但是,在这种特殊情况下,我实际上需要等待“直到用户完成键入”。 Ie, I don't want to just wait for the first time that the
TextChanged
event fires, I want to wait until at least 500ms have passed since the last time it fired before continuing the execution of my method. 即,我不想仅等待
TextChanged
事件第一次触发,而是要等待自上次触发以来至少经过500毫秒,然后再继续执行我的方法。
Currently I have something that uses timers where every time the TextChanged
event fires the timer is restarted and when the timer's Tick
event fires it means that the user "has finished typing". 当前,我使用计时器,每次
TextChanged
事件触发时,计时器都会重新启动,而计时器的Tick
事件触发时,则意味着用户“已完成键入”。
There are three main problems with this approach right now though: 但是,此方法目前存在三个主要问题:
Timer
for this Timer
更好/更干净的方法 Tick
event handler, that's not changed though. Tick
事件处理程序中,尽管没有改变。 How can I accomplish this? 我该怎么做?
This is very easy to do using ReactiveUI . 使用ReactiveUI非常容易做到这一点。 Look at the example on the main page.
查看主页上的示例。 It does more or less exactly what you are after.
它或多或少地精确地满足了您的需求。
It is based on Reactive Extensions (RX) for .Net and is written to make things like these easy. 它基于.Net的Reactive Extensions(RX),旨在简化此类操作。 If using ReactiveUI is not an option then I suggest you look at RX and how ReactiveUI implements this.
如果不选择使用ReactiveUI,则建议您查看RX以及ReactiveUI如何实现这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.