2013-09-05 65 views
0

我已经为TextBlock事件创建了一个KeyUp事件的方法,该事件过滤了联系人。所有这些工作正常。如何检查空闲时间

现在,我不想过滤每个KeyUp事件,而是要检查用户是否闲置1-1.5秒。在触发过滤器方法之前。

我绝对是C#的新手,所以我甚至不知道如何解决这个问题。我怎样才能做到这一点?

+0

什么决定“怠速”?延迟过滤的原因是什么? – Cheesebaron

+0

@Cheesebaron当用户停止输入时 –

+0

使用计时器并在那里过滤 –

回答

1

如果你想一次在C#什么,然后你最好的选择是使用

StopWatchhttp://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx

Stopwatch stopWatch = new Stopwatch(); 
    stopWatch.Start(); 
    stopWatch.Stop(); 
    // Get the elapsed time as a TimeSpan value. 
    TimeSpan ts = stopWatch.Elapsed; 

我期待通过的文件,我似乎无法找到秒表图书馆所以在这里尝试是一个alt解决方案,我知道工程 http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatchertimer.aspx

// DispatcherTimer setup 
dispatcherTimer = new System.Windows.Threading.DispatcherTimer(); 
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick); 
dispatcherTimer.Interval = new TimeSpan(0,0,1); 
dispatcherTimer.Start(); 

private void dispatcherTimer_Tick(object sender, EventArgs e) 
{ 
    //check your users text 
} 
+0

谢谢,现在试用:) –