private void InitializeComponent()
{    
this.timer1 = new System.Timers.Timer();
((System.ComponentModel.ISupportInitialize)(this.timer1)).BeginInit();
// 
// timer1
// 
this.timer1.Enabled = true;
this.timer1.Interval = 1800000;
this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Elapsed);
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.timer1)).EndInit(); }
#endregion private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
SqlConnection SqlConn = new SqlConnection(ConfigurationSettings.AppSettings["strSqlConn"]);
SqlConn.Open ();
string strSql ="Update T_User Set point=point+1 where user_id=48";
SqlCommand myCommand = new SqlCommand(strSql,SqlConn);
myCommand.ExecuteNonQuery();
SqlConn.Close();
}
测试通过!

解决方案 »

  1.   

    注意 : using System.Threading;
      

  2.   

    对, xinuaile(喜怒哀乐)我也需要这个问题答案!
    也想用线程池提供的功能。
    System.Threading.Timer比System.Timers.Timer耗的资源要少!
    up!!同样的问题如下:
    我是在一个web application中使用Timer。
    由Global.asax在应用启动的时候让timer启动!Timer的功能,写在一个class中!
    也是只运行了一次!!//一个方法中:
    System.Threading.Timer aTimer = new System.Threading.Timer(new System.Threading.TimerCallback(OnTimerCallBack),null,0,1000);
    ApplicationLog.WriteInfo("Timer is begin");
    //delegate:
    public static void OnTimerCallBack(object source){
    ApplicationLog.WriteInfo("call back!");
    }执行后,委托方法只执行了一次!为什么呢?
    后来用System.Timers.Timer倒是可以执行了!但是我想用线程池呀!!
    好像System.Timers.Timer比System.Threading.Timer耗费资源!
    我的程序是服务器端的,需要长时间执行!
    哪知道怎么回事??谢谢!
      

  3.   

    see more in ms-help://MS.MSDNQTR.2003FEB.2052/cpref/html/frlrfSystemThreading.htm