Timer事件

         public static void Main() {
            // Create a Timer object that knows to call our TimerCallback  
            // method once every 2000 milliseconds. 
            Timer t = new Timer(TimerCallback, null, 0, 2000);

            // Wait for the user to hit <Enter> 
            Console.ReadLine();
        }

        private static void TimerCallback(Object o)
        {
            // Display the date/time when this method got called. 
            Console.WriteLine("In TimerCallback: " + DateTime.Now);

            // Force a garbage collection to occur for this demo. 
            GC.Collect();
        } 

        

         public static void Main() {
            // Create a Timer object that knows to call our TimerCallback  
            // method once every 2000 milliseconds.  
            new Timer(TimerCallback, null, 0, 2000);

            // Wait for the user to hit <Enter> 
            Console.ReadLine();
        }

        private static void TimerCallback(Object o)
        {
            // Display the date/time when this method got called. 
            Console.WriteLine("In TimerCallback: " + DateTime.Now);

            // Force a garbage collection to occur for this demo. 
            GC.Collect();
        } 

       

 

posted @ 2012-05-31 18:57  狩猪逮兔  阅读(212)  评论(0编辑  收藏  举报