private void StartWorkerThreadFunc(bool forced)
        {
            void Reset()
            {
                _thread = null;
                _timer.Start();
            }

            // If there is a thread, the job is already running
            if (_thread != null)
            {
                return;
            }

            try
            {
                _timer.Stop();
                _timer.Interval = GetJobInterval();

                _thread = new Thread(() =>
                {
                    DoServiceJob(forced);
                    Reset();
                });
                _thread.Name         = "WorkerThreadFunc";
                _thread.IsBackground = true;
                _thread.Start();
            }
            catch (Exception e)
            {
                CriticalErrorLogger.LogCriticalError(e, ServiceName);
                //throw; REMOVED this throw here because it would cause the service to stop in the event of a failling execution
                Reset();
            }
        }
 protected override void OnStop()
 {
     try
     {
         _timer?.Stop();
         _timer?.Dispose();
         _thread?.Abort();
         ServiceStopping();
     }
     catch (Exception e)
     {
         CriticalErrorLogger.LogCriticalError(e, ServiceName);
     }
 }
        protected override void OnStart(string[] args)
        {
            try
            {
                ServiceStarting();

                this._timer           = new System.Timers.Timer(GetFirstExecutionInterval());
                this._timer.AutoReset = true;
                this._timer.Elapsed  += _timer_Elapsed;
                this._timer.Enabled   = true;
            }
            catch (Exception e)
            {
                CriticalErrorLogger.LogCriticalError(e, ServiceName);
                throw;
            }
        }
        public static void Run(FarenzenaServiceBase serviceToRun, params string[] args)
        {
            try
            {
                if (args.Length == 0)
                {
                    ServiceBase[] ServicesToRun;
                    ServicesToRun = new ServiceBase[]
                    {
                        serviceToRun
                    };
                    ServiceBase.Run(ServicesToRun);
                }
                else
                {
                    serviceToRun.Interactive = true;
                    AllocConsole();
                    switch (args[0])
                    {
                    case "config":
                        serviceToRun.ConfigureService();
                        break;

                    case "run":
                        serviceToRun.OnStart(args);
                        Console.WriteLine("The service is running as an application. Press the ENTER key to exit.");
                        Console.ReadLine();
                        serviceToRun.Stop();
                        break;

                    default:
                        throw new NotImplementedException();
                    }
                }
            }
            catch (Exception e)
            {
                CriticalErrorLogger.LogCriticalError(e, serviceToRun.ServiceName);
                throw;
            }
        }