【问题标题】:Not able to call event through ElapsedEventHandler in windows service in C# .Net无法通过 C# .Net 中 Windows 服务中的 ElapsedEventHandler 调用事件
【发布时间】:2013-06-18 19:40:42
【问题描述】:

我正在尝试编写一个服务来运行创建水晶报表的任务。我使用 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();
        }

【问题讨论】:

    标签: c# windows-task-scheduler


    【解决方案1】:

    您需要在计时器上调用Start 才能真正启动它。

    【讨论】:

      猜你喜欢
      • 2016-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-09
      相关资源
      最近更新 更多