zoukankan      html  css  js  c++  java
  • 时钟操作类

    namespace mynamespace 
    {
        public delegate void methodDelegate(object o);
        public class TimerHandler
        {
            private static methodDelegate _method;
            private static methodDelegate method
            {
                get { return _method; }
            }
            private static Timer _timer = null;
            private static Timer timer
            {
                get
                {
                    if (_timer != null)
                    {
                        return _timer;
                    }
                    else
                    {
                        return new Timer(new TimerCallback(method), null, Timeout.Infinite, Timeout.Infinite);
                    }
                }
            }
    
            /// <summary>
            /// 启动计时器
            /// </summary>
            public void Start(methodDelegate method)
            {
                _method = method;
                int ScanInterval = 6 * 1000;//ms,6s默认时间
                if (System.Configuration.ConfigurationSettings.AppSettings["ScanInterval"] != null)
                {
                    ScanInterval = Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings["ScanInterval"]) * 1000;
                }
                timer.Change(0, ScanInterval);
            }
    
            /// <summary>
            /// 停止计时器
            /// </summary>
            public void Stop()
            {
                timer.Change(Timeout.Infinite, Timeout.Infinite);
            }
    
    
        }
    }

     使用:

    TimerHandler t = new TimerHandler();
            t.Start(methodName);
  • 相关阅读:
    sed
    zabbix时间不同步
    zabbix-agent安装
    zabbix安装(网络)
    sendmail启动报错
    12306:被骂十年不吭声,终成大器
    一文带你看清HTTP所有概念(转)
    为什么 K8s 在阿里能成功(转)
    一文解读融资方式
    一文解读工业互联网 (转)
  • 原文地址:https://www.cnblogs.com/mahatmasmile/p/3396263.html
Copyright © 2011-2022 走看看