-1

I need to to notify the user when the battery level is exact 20%. Currently I am using a Timer to check the SystemInformation.PowerStatus.BatteryLifePercent status repeatedly in a fixed interval. Is there any better and efficient way to do it?

Edit: I want to make it work on laptops.

Sambit
  • 424
  • 6
  • 15
  • 3
    You didn't say what kind of device you're trying to work on. Is it a phone? Is it a laptop? What system do you target? We're not going to guess. – MarcinJuraszek May 12 '14 at 06:42
  • Depends on device and what are you using to get that `BatteryLifePercent` it is from `Systeminfo` or `PowerStatus` class or is it some custom 3rd party class or app? But there is nothing wrong with checking it with `Timer` – Milan Halada May 12 '14 at 06:54
  • possible duplicate of [C#, Constantly monitor battery level](http://stackoverflow.com/questions/17832969/c-constantly-monitor-battery-level) – DIF May 12 '14 at 07:05

1 Answers1

1

This answer C#, Constantly monitor battery level proposes to register to the SystemEvents.PowerModeChanged-Event like this:

static void SystemEvents_PowerModeChanged(object sender, Microsoft.Win32.PowerModeChangedEventArgs e)
{
    if (e.Mode == Microsoft.Win32.PowerModes.StatusChange)
    {
        if (pw.BatteryLifeRemaining == 20)
        {
         //Do stuff here
        }
    }
}
Community
  • 1
  • 1
DIF
  • 2,470
  • 6
  • 35
  • 49