title: Automatic battery level check in C#
body: <p>I'm working on a speech recognition program in C# and I've compiled a few lines of code that speaks back the current battery level when I say "battery level".</p>
  
  <pre><code>if (e.Result.Text.ToLower() == "battery level")
  {
  System.Management.ManagementClass wmi = new System.Management.ManagementClass("Win32_Battery");
  var allBatteries = wmi.GetInstances();
  //String estimatedChargeRemaining = String.Empty;
  int batteryLevel = 0;
  
  foreach (var battery in allBatteries)
  {
      batteryLevel = Convert.ToInt32(battery["EstimatedChargeRemaining"]);
  }
  
  if(batteryLevel &lt; 25)       
     JARVIS.Speak("Warning, Battery level has dropped below 25%");
  else //Guessing you want else
     JARVIS.Speak("The battery level is at: " + batteryLevel.ToString() + "%");
  return;
  }
  </code></pre>
  
  <p>Instead of this line happening only when I say "battery level" I want it to automatically check the battery level every 15mins and automatically report back to me via speech if the battery level has dropped bellow 25%:</p>
  
  <pre><code>if(batteryLevel &lt; 25)       
     JARVIS.Speak("Warning, Battery level has dropped below 25%");
  </code></pre>
  
  <p>I am guessing I will require a timer but other than that I have no idea.</p>
  
  <p>Thanks.</p>