隨筆-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#
          主站蜘蛛池模板: 安龙县| 托克逊县| 奉新县| 犍为县| 汉沽区| 山西省| 新津县| 凤凰县| 崇阳县| 凤山县| 新野县| 金川县| 赤城县| 焉耆| 苍梧县| 铅山县| 新化县| 山东省| 蓝山县| 塔城市| 华坪县| 宜川县| 大邑县| 天门市| 民权县| 阿尔山市| 鹿泉市| 手机| 静宁县| 乐昌市| 安西县| 思茅市| 霞浦县| 翁源县| 岫岩| 友谊县| 泌阳县| 浦县| 固原市| 临西县| 宁安市|