Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法通过C#Net中windows服务中的ElapsedEventHandler调用事件_C#_Windows Task Scheduler - Fatal编程技术网

无法通过C#Net中windows服务中的ElapsedEventHandler调用事件

无法通过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");

我正在尝试编写一个服务来运行创建crystal报表的任务。我使用ElapsedEventHandler在Start中调用一个方法“timer_appeased”。但是这个方法没有被调用

任何有关这方面的帮助都将不胜感激

代码如下:

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
,才能真正启动计时器