无法通过C#Net中windows服务中的ElapsedEventHandler调用事件
我正在尝试编写一个服务来运行创建crystal报表的任务。我使用ElapsedEventHandler在Start中调用一个方法“timer_appeased”。但是这个方法没有被调用 任何有关这方面的帮助都将不胜感激 代码如下:无法通过C#Net中windows服务中的ElapsedEventHandler调用事件,c#,windows-task-scheduler,C#,Windows Task Scheduler,我正在尝试编写一个服务来运行创建crystal报表的任务。我使用ElapsedEventHandler在Start中调用一个方法“timer_appeased”。但是这个方法没有被调用 任何有关这方面的帮助都将不胜感激 代码如下: public void Start() { // OnStart(new string[0]); Console.WriteLine("Windows Service Started");
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();
}
您需要在计时器上调用
Start
,才能真正启动计时器