我正在尝试编写一个服务来运行创建水晶报告的任务。我正在使用 ElapsedEventHandler 在 Start 中调用方法“timer_Elapsed”。但是这个方法没有被调用。
对此的任何帮助将不胜感激。
这是代码:
public void Start()
{
// OnStart(new string[0]);
Console.WriteLine("Windows Service Started");
timer1 = new System.Timers.Timer();
((System.ComponentModel.ISupportInitialize)(this.timer1)).BeginInit();
timer1.Enabled = true;
this.timer1.Interval = 2000;
this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_Elapsed);
this.timer1.Interval = 2000;
//timer1.Enabled = true;
Log("Service Started successfully!!");
timeCurrent = DateTime.Now.ToString();
Log("Service Started at" + " " + timeCurrent);
}
private void timer_Elapsed(object sender, EventArgs e)
{
GenerateCrystalReports();
}