随笔-7  评论-24  文章-102  trackbacks-0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    
class Program
    
{
        
static void Main(string[] args)
        
{
            AddRoomTimer timer 
= new AddRoomTimer();
            
while (true)
            
{
                
if (AddRoomTimer.COUNT > 0)
                
{
                    Console.WriteLine(
string.Format("第{0}次调用"101 - AddRoomTimer.COUNT));
                    AddRoomTimer.COUNT
--;
                }

            }


            
//System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);

            
//System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
        }

    }


    
public class AddRoomTimer
    
{
        
//静态计数器变量
        public static int COUNT = 0;
        public static System.Threading.Timer timer;

        
//静态构造, 最多运行一次
        static AddRoomTimer()
        
{
            
//多线程定时器, 每隔 10000毫秒调用一次被委托的方法 TimerCallBack
            timer = new System.Threading.Timer(TimerCallBack, null010000);
        }


        
private static void TimerCallBack(object obj)
        
{
            
//打印一次时间, 测试用
            Console.WriteLine(DateTime.Now.ToString());
            
//计数器变量重置
            COUNT = 100;
        }

    }

}

posted on 2009-06-16 00:11 黄小二 阅读(1327) 评论(0)  编辑  收藏 所属分类: ASP.NETC#

只有注册用户登录后才能发表评论。


网站导航: