using System;

namespace ZocMonLib.Service.Reduce
{
    public class ReduceServiceRunner
    {
        private readonly ISystemLogger _logger;
        private System.Timers.Timer _timer;
        private readonly ISettings _settings;

        public ReduceServiceRunner(ISettings settings)
        {
            _logger = settings.LoggerProvider.CreateLogger(typeof(ReduceServiceRunner));
            _settings = settings;
        }

        public void Start()
        {
            Log("ReduceServiceRunner - Starting");

            if (_settings.Enabled)
            {
                Log("ReduceServiceRunner - Timing setup");

                _timer = new System.Timers.Timer(_settings.AutoReduceInterval) { AutoReset = true };
                _timer.Elapsed += (sender, eventArgs) =>
                {
                    Log(String.Format(" - Executing Reduce Start: {0:yyyy/MM/dd_HH:mm:ss-fff}", DateTime.Now));
                    _settings.RecordReduce.ReduceAll(false);
                    Log(String.Format(" - Executing Reduce Finish: {0:yyyy/MM/dd_HH:mm:ss-fff}", DateTime.Now));
                };

                _timer.Start();
            }
        }

        public void Stop()
        {
            Log("ReduceServiceRunner - Finished");

            if (_timer != null)
                _timer.Stop();
        }

        private void Log(string info)
        {
            _logger.Info(info);
            Console.WriteLine(info);
        }
    }
}
using System;

namespace ZocMonLib.Service.Reduce
{
    public class ReduceServiceRunner
    {
        private readonly ISystemLogger _logger;
        private System.Timers.Timer _timer;
        private readonly ISettings _settings;

        public ReduceServiceRunner(ISettings settings)
        {
            _logger = settings.LoggerProvider.CreateLogger(typeof(ReduceServiceRunner));
            _settings = settings;
        }

        public void Start()
        {
            Log("ReduceServiceRunner - Starting");

            if (_settings.Enabled)
            {
                Log("ReduceServiceRunner - Timing setup");

                _timer = new System.Timers.Timer(_settings.AutoReduceInterval) { AutoReset = false };
                _timer.Elapsed += (sender, eventArgs) =>
                {
                    Log(String.Format(" - Executing Reduce Start: {0:yyyy/MM/dd_HH:mm:ss-fff}", DateTime.Now));
                    _settings.RecordReduce.ReduceAll(false);
                    Log(String.Format(" - Executing Reduce Finish: {0:yyyy/MM/dd_HH:mm:ss-fff}", DateTime.Now));
                    _timer.Start();
                };

                _timer.Start();
            }
        }

        public void Stop()
        {
            Log("ReduceServiceRunner - Finished");

            if (_timer != null)
                _timer.Stop();
        }

        private void Log(string info)
        {
            _logger.Info(info);
            Console.WriteLine(info);
        }
    }
}
Set up timer so that it can't start reducing while previous reduction is still in progress.
Set up timer so that it can't start reducing while previous reduction is still in progress.
