如果要知道数据库的变化,还不如用SqlServer Notification Service

解决方案 »

  1.   

    System.Timers.Timer myTimer = new System.Timers.Timer();
    -->
    private System.Timers.Timer myTimer; 
    public CNUCService()
    {
       InitializeComponent();
       myTimer.Interval = 1000; 
       myTimer.Enabled = true; 
    }
    private void InitializeComponent()
    {
    this.timer1 = new System.Timers.Timer();
    ((System.ComponentModel.ISupportInitialize)(this.timer1)).BeginInit();
    this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Elapsed);
    }
      

  2.   

    用System.Thread中的Timer类,用后台线程来实现是最好的
      

  3.   

    to chenbinghui(阿炳)
       因为我要实现一个windows服务,该服务需要定时(1秒)扫描
    数据库的某个表,只能1秒扫描一次,但是我却不会用timer类,而
    且还要把timer的控制和服务的OnStart()、OnStop()结合起来。
    to  spring_ok(SpringDotNet) 
        谢谢,但是我还是不明白,OnStart()和OnStop()里边写什么
    呢?
       
       我是这样想的:
       当服务安装以后
       如果启动服务,那么OnStart()就会触发mytimer对象开始计时,
    每隔1000毫秒,便扫描一次数据
       如果停止服务,那么OnStop()就会使该操作停掉(扫描数据库)
       你能不能再帮我写详细一点?谢谢啦!
      

  4.   

    像你这种情况,onstart和onstop中就什么也不用写啦。
      

  5.   

    System.Windows.Forms.Timer是应用于WinForm中的,它是通过Windows消息机制实现的,类似于VB或Delphi中的Timer控件,内部使用API  SetTimer实现的。它的主要缺点是计时不精确,而且必须有消息循环,Console  Application无法使用。  
     
    System.Timers.Timer和System.Threading.Timer非常类似,它们是通过.NET  Thread  Pool实现的,轻量,计时精确,对应用程序、消息没有特别的要求。System.Timers.Timer还可以应用于WinForm,完全取代上面的Timer控件。它们的缺点是不支持直接的拖放,需要手工编码。  推荐使用System.Timers.Timer,代码这个地方有,自己读读就好.
    ms-help://MS.VSCC/MS.MSDNVS.2052/cpref/html/frlrfsystemtimerstimerclasstopic.htm还有,如果要up的话,最好能说说那个地方不明白,或者没有说清楚.
      

  6.   

    ms-help://MS.VSCC/MS.MSDNVS.2052/cpref/html/frlrfsystemtimerstimerclasstopic.htm