1

以下に定義されているタイマーがあります。タイマーは長時間実行されるタスクを実行します。私が抱えている問題は、タイマーが実行されているときに間隔が再び経過し、別のタイマーの実行が開始されること_timer_Elapsedです。タイマーが終了した後、タイマーを 1 間隔で実行するにはどうすればよいですか。現在の方法では、一度に複数のタイマー実行が発生する可能性があり、コードにあらゆる種類の問題が発生します。

protected override void OnStart(string[] args)
        {

           _timer = new System.Timers.Timer();
           _timer.AutoReset = false;
           _timer.Interval = (Convert.ToInt32(ConfigurationManager.AppSettings["CheckInterval"]));
           _timer.Elapsed += new System.Timers.ElapsedEventHandler(_timer_Elapsed);
           _timer.Enabled = true;
           _timer.Start(); // Start timer 

        }


 public static void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            try
            {
                _timer.Interval = (Convert.ToInt32(ConfigurationManager.AppSettings["CheckInterval"])); 

                BLLGenericResult SystemCheckItems_Result = ServiceItemOperations.CheckItems(); // Long Running Task

            }
            catch (Exception ex)
            {
                // Exception handling...
            }
            finally
            {
                _timer.Start();
            }
        }
4

2 に答える 2