public void Start()
 {
     if (!started)
     {
         lock (lockObject)
         {
             if (!started)
             {
                 RtqInternals.ResetTicksHolderInMemoryState();
                 localTaskQueue.Start();
                 foreach (var handlerManager in handlerManagers)
                 {
                     periodicJobRunner.RunPeriodicJob(handlerManager.JobId,
                                                      delayBetweenIterations: consumerSettings.PeriodicInterval,
                                                      handlerManager.RunJobIteration);
                 }
                 periodicJobRunner.RunPeriodicJob(reportConsumerStateToGraphitePeriodicJob.JobId,
                                                  delayBetweenIterations: TimeSpan.FromMinutes(1),
                                                  reportConsumerStateToGraphitePeriodicJob.RunJobIteration);
                 started = true;
                 var handlerManagerIds = string.Join("\r\n", handlerManagers.Select(x => x.JobId));
                 logger.Info("Start RtqConsumer: schedule handlerManagers[{HandlerManagersCount}] with period {Period}:\r\n{HandlerManagerIds}",
                             new { HandlerManagersCount = handlerManagers.Count, Period = consumerSettings.PeriodicInterval, HandlerManagerIds = handlerManagerIds });
             }
         }
     }
 }
 public void Stop()
 {
     if (started)
     {
         lock (lockObject)
         {
             if (started)
             {
                 logger.Info("Stopping RtqConsumer");
                 periodicJobRunner.StopPeriodicJob(reportConsumerStateToGraphitePeriodicJob.JobId);
                 Task.WaitAll(handlerManagers.Select(theHandlerManager => Task.Factory.StartNew(() =>
                 {
                     // comment to prevent ugly reformat
                     periodicJobRunner.StopPeriodicJob(theHandlerManager.JobId);
                 })).ToArray());
                 localTaskQueue.StopAndWait(timeout: TimeSpan.FromSeconds(100));
                 RtqInternals.ResetTicksHolderInMemoryState();
                 started = false;
                 logger.Info("RtqConsumer stopped");
             }
         }
     }
 }