zoukankan      html  css  js  c++  java
  • wpf 输入停止一段时间后。执行事件

    View Code
     System.Timers.Timer t;
            DateTime lastInputTime = DateTime.MinValue;
           
            private void textBox1_PreviewKeyDown(object sender, KeyEventArgs e)
            {
                if (t!=null)
                {
                    t.Stop();
                }
                t = new System.Timers.Timer();
                t.Interval = 3000;
                t.Elapsed += new System.Timers.ElapsedEventHandler(theout);//到达时间的时候执行事件;
                t.AutoReset = false;//设置是执行一次(false)还是一直执行(true);   
                t.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件;
    
    
                //if (lastInputTime == DateTime.MinValue)
                //{
                //    lastInputTime = DateTime.Now;
                //}
                //else
                //{
                //    var nowInputTime = DateTime.Now;
                //    if ((nowInputTime - lastInputTime).Seconds > 3)
                //    {
                //        MessageBox.Show("大于");
                //    }
                //    lastInputTime = nowInputTime;
    
                //}
    
    
            }
            public void theout(object source, System.Timers.ElapsedEventArgs e)
            {
                MessageBox.Show(e.SignalTime.ToString());
            }
  • 相关阅读:
    grunt 使用比较
    一些技术要点
    git 使用笔记
    oo的一些概念
    借用构造函数继承非原型
    bower解决js的依赖管理
    需要了解的一些东西
    一些常用的代码
    js模式(一):单例模式
    写给自己的计划
  • 原文地址:https://www.cnblogs.com/FaDeKongJian/p/2954916.html
Copyright © 2011-2022 走看看