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();
                
    //}
            }


        }


    }

  • 相关阅读:
    js 和 jquery 动态创建元素
    京东火车票正式上线:开卖火车票!
    网易旗下新域名泰坦尼克曝光:要出航海题材新作
    Facebook CEO扎克伯格造访日本,获首相会见
    struts2教程系列
    hadoop方面的资料
    FlexViewer入门资料
    深入浅出Flex Viewer系列
    flex css
    【Flex4中的皮肤使用组件数据】系列
  • 原文地址:https://www.cnblogs.com/kokoliu/p/1171621.html
Copyright © 2011-2022 走看看