public void Run(IRepeatingTask repeatingTask)
        {

            if (repeatingTask == null)
                throw new ArgumentNullException("repeatingTask");

            EnterRunningState();

            bool stopRequested = false;

            try
            {

                while (!stopRequested)
                {

                    var repeatingTaskResult = DoTask(repeatingTask);

                    if (repeatingTaskResult.IsWorkCompleted)
                    {
                        Stop();
                    }

                    stopRequested = CheckStopRequested();

                    if ((!stopRequested) && (!repeatingTaskResult.WasWorkDone) && PollInterval.HasValue)
                    {
                        ThreadPauser.Pause(PollInterval.Value);

                        stopRequested = CheckStopRequested();
                    }

                }
            }
            finally
            {
                EnterStoppedState();
            }

        }
        private RepeatingTaskResult DoTask(IRepeatingTask repeatingTask)
        {
            RepeatingTaskResult output = null;

            try
            {
                output = repeatingTask.DoTask();
            }
            catch (Exception exception)
            {
                if (ExceptionHandler != null)
                {
                    ExceptionHandler.HandleException(exception);
                }
                else
                {
                    throw;
                }
            }

            if (output == null)
            {
                output = new RepeatingTaskResult(false, false);
            }

            return output;

        }