Recently I have been making a program which finds out the battery percentage of the user's computer. I'm trying to figure out which method to use. I've seen there are two ways of doing it such as:
PowerStatus powerStatus = SystemInformation.PowerStatus;
if (powerStatus.BatteryLifePercent < 0.1)
{
MessageBox.Show("Battery is at 10%");
}
and
ManagementClass wmi = new ManagementClass("Win32_Battery");
var allBatteries = wmi.GetInstances();
foreach (var battery in allBatteries)
{
int batteryLevel = Convert.ToInt32(battery["EstimatedChargeRemaining"]);
if (batteryLevel < 10)
{
MessageBox.Show("Battery is at 10%");
}
I'm not sure which method to use.