zoukankan      html  css  js  c++  java
  • System.Threading.TimerCallback 永不停止的定时器

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Threading;

    namespace ConsoleApplication1
    {
        
    class TimerExample
        
    {
            
    static void Main(string[] args)
            
    {
                AutoResetEvent autoEvent 
    = new AutoResetEvent(false);
                StatusChecker statusChecker 
    = new StatusChecker(10);

                TimerCallback timerDelegate 
    = new TimerCallback(statusChecker.CheckStatus);

                Console.WriteLine(
    "服务器开始扫描:" +
                DateTime.Now.ToString(
    "h:mm:ss.fff"));
                Timer stateTimer 
    =
                
    new Timer(timerDelegate, autoEvent, 10005000);

                autoEvent.WaitOne(
    -1false);

                stateTimer.Dispose();
                Console.WriteLine(
    "xxxxxxxx."); 


            }



          

        }

        
    class StatusChecker
        
    {
            
    int invokeCount, maxCount;

            
    public StatusChecker(int count)
            
    {
                invokeCount 
    = 0;
                maxCount 
    = count;
            }


            
    // This method is called by the timer delegate.
            public void CheckStatus(Object stateInfo)
            
    {
                
    //AutoResetEvent autoEvent = (AutoResetEvent)stateInfo;

               
                Console.WriteLine(
    "{0} Checking status {1,2}.",
                    DateTime.Now.ToString(
    "h:mm:ss.fff"),
                    (
    ++invokeCount).ToString());

                
    //if (invokeCount == maxCount)
                
    //{
                
    //    // Reset the counter and signal Main.
                
    //    invokeCount = 0;
                
    //    autoEvent.Set();
                
    //}
            }


        }


    }

  • 相关阅读:
    不会写研发部门OKR?来这里看看吧
    HR 必须了解的绩效考核
    成功的OKR复盘会需要注意什么
    effective解读-第一条 静态工厂创建对象代替构造器
    灾难恢复:邮箱数据库操作总结:整理 查询邮箱数据库大小和空白数据大小(重要文档)
    Exchange传输队列queue数据库mail.que文件越来越大(重要文档)
    Exchange2016邮件流(重要文档)
    Exchange2016服务器使用到的9个端口
    VMware EXSI 启用vMotion
    Exchange2016DAG的配置
  • 原文地址:https://www.cnblogs.com/kokoliu/p/1171621.html
Copyright © 2011-2022 走看看