请教c#中的Timer控件
我写了一个windows services,从组建中增加了一个Time控件,在timer1_Tick事件中写数据库,代码如下:
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
protected override void OnStart(string[] args)
{
this.timer1.Enabled = true;
this.LogMessage();
}
protected override void OnStop()
{
this.timer1.Enabled = false;
}
private void LogMessage()
{
SqlConnection conn = new SqlConnection("server=127.0.01;database=NetworkServicer;uid=sa;pwd=sa");
string sql_s = " insert into [PingLog] ([EventDatetime],[EventLevel], [EventMessage]) VALUES ('2010-01-21','111','11')";
SqlCommand comm = new SqlCommand(sql_s, conn);
conn.Open();
comm.ExecuteNonQuery();
conn.Close();
}
private void timer1_Tick(object sender, EventArgs e)
{
this.LogMessage();
}
每次只有开始时写入的一条记录,timer1_Tick事件怎么没有执行?