title: My timer loop intermittently slows down, not sure why
body: <p>I have a API request queue that I have looped using <code>System.Timers.Timer</code>. I set it up like this:</p>
  
  <pre><code>    private static void SetupTimerLoop()
      {
          queueLoopTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
          queueLoopTimer.Interval = 100;
          queueLoopTimer.Start();
      }
  </code></pre>
  
  <p>Periodically <code>OnTimedEvent</code> will only get called once every second, almost exactly for large spans of time. It will then speed back up to once every 100ms. I cannot accurately reproduce these results, sometimes it happens, sometimes it does not. I have watched my CPU usage and it doesn't spike during these times of slowdown, if anything it goes down.</p>
  
  <p>If I make breakpoints it shows that the timers interval is still only 100ms. </p>
  
  <p>What could be going on here? Is there anything I can do to further troubleshoot this?</p>
  
  <p>Potentially related, when this happens all my HTTP requests that are initiated from the loop (these are put onto Tasks so they return asynchronously) stop returning. </p>
  
  <p>Request related: </p>
  
  <pre><code>    private T Get&lt;T&gt;(string endpoint, IRequest request) where T : class
      {
          var client = InitHttpClient();
  
          string debug = BaseUrl + endpoint + ToQueryString(request);
  
          HttpResponseMessage response = client.GetAsync(BaseUrl + endpoint + ToQueryString(request)).Result;
          string body = response.Content.ReadAsStringAsync().Result;
  
          if (response.IsSuccessStatusCode)
          {
              T result = JsonConvert.DeserializeObject&lt;T&gt;(body, _serializerSettings);
  
              return result;
          }
  
          var error = JsonConvert.DeserializeObject&lt;HelpScoutError&gt;(body);
          throw new HelpScoutApiException(error, body);                                                                 
      }
  </code></pre>
  
  <p>I never get to: <code>string body = response.Content.ReadAsStringAsync().Result;</code> as long as the loop seems to be running slow.</p>
  
  <p>Not sure if that could have something to do with it, hopefully you guys have some insight.</p>
  
  <p>Edit: I don't flood the API with requests. I throttle the number of requests that go out per rolling 60-second period. During that time I just use an if statement to pass over the API call for that loop.</p>