且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何实现计时器的Tick事件?

更新时间:2023-11-17 15:22:04

嗯。

这不是你的代码,或者它没有编译,你没有注意到。

这个:

Um.
That isn't your code, or it doesn't compile, and you haven't noticed.
This:
private bool textChanged = false;

这:

This:

private void textChanged(object sender, EventArg e)
{
   ...

and

And

if (textChanged && lastChange > DateTime.Now.AddSeconds(-2)) // wait 2 second for changes
{
   ...

由于两个名称之间存在歧义,因此无法编译。 (并且它是 EventArgs ,而不是事件处理程序声明中的EventArg



所以首先让它进行编译,然后从那里开始工作。如果没有你实际运行的代码,我们什么也做不了!

Will not compile as there is an ambiguity between the two names. (And it's EventArgs, not EventArg in the event handler declaration.

So start by getting it to compile, and then work from there. We can't do anything without the code you are actually running!


这就是我的意思我的上述评论意味着:



Here, this is what I meant by my above comment:

Timer _InputTimer = new Timer();
string _Input = "";

private void _InitTimer()
{
    _InputTimer.Tick += new EventHandler(_InputTimer_Tick);
    _InputTimer.Interval = 2000;
    _InputTimer.Start();
}

private void _InputTimer_Tick(object sender, EventArgs е)
{
    if (_Input != txtInput.Text){
        _InputTimer.Stop();
        _Input = txtInput.Text;
        _DoSearch();
    }
}

private void _DoSearch()
{
    MessageBox.Show("Now's where you might multi-thread");
}