在web应用程序和winForm应用程序中都可以使用Timer控件定时
在控制台程序中怎么定时触发一个事件啊?

解决方案 »

  1.   

    使用System.Threading.Timer 创建一个定时线程
      

  2.   

    使用了System.Threading.Timer
    ManualResetEvent timerevent = new ManualResetEvent(false);
    Timer timer = new Timer( new TimerCallback(this.TimerMethod), null, TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(10) );public void TimerMethod(object state)
    {
            Console.WriteLine("\rThe Timer invoked this method.");
            //查找定时定位表中是否有记录
    DataTable recordTable = CheckTable();
    if( recordTable.Rows.Count > 0 )//判断是否有记录以及是否发送请求
    {
    SendRequest( recordTable );
    }
    }
    我试过了,如果只有 Console.WriteLine("\rThe Timer invoked this method.");这一句程序可以正常运行,每10秒钟输出一次
    但是加上下面的几句,调用另外的方法,定时程序只执行一次后就没有反应了
    请问是怎么回事啊