隨筆-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 黃小二 閱讀(1342) 評論(0)  編輯  收藏 所屬分類: ASP.NETC#
          主站蜘蛛池模板: 金溪县| 同仁县| 吴川市| 奈曼旗| 黄梅县| 宁蒗| 崇义县| 海盐县| 三河市| 喀什市| 衡阳县| 香港| 江油市| 焦作市| 农安县| 平舆县| 和静县| 贡山| 宣城市| 桂林市| 大竹县| 健康| 南和县| 黔南| 定西市| 嵩明县| 雅安市| 蒙城县| 庆元县| 梅河口市| 汪清县| 石棉县| 姜堰市| 桑日县| 醴陵市| 繁峙县| 普定县| 彰武县| 沂源县| 巴青县| 永和县|