Beispiel #1
0
 private void SetUpdatedBatteryCondition(BatteryCondition batteryCondition)
 {
     batteryListBox.Items.Clear();
     batteryListBox.Items.Add($"Battery plug type: \t\t{batteryCondition.PlugType}");
     batteryListBox.Items.Add($"Battery charge status: \t{batteryCondition.ChargeStatus}");
     batteryListBox.Items.Add($"Battery estimated runtime: \t{batteryCondition.EstimatedRunTime}");
 }
 private void UpdateBatteryCondition(BatteryCondition batteryCondition)
 {
     if (batteryListBox.InvokeRequired)
     {
         UpdateBatteryConditionCallBack callBack = UpdateBatteryCondition;
         Invoke(callBack, batteryCondition);
     }
     else
     {
         SetUpdatedBatteryCondition(batteryCondition);
     }
 }
Beispiel #3
0
 private void UpdateBatteryCondition(BatteryCondition batteryCondition)
 {
     // InvokeRequired required compares the thread ID of the
     // calling thread to the thread ID of the creating thread.
     // If these threads are different, it returns true.
     if (this.batteryListBox.InvokeRequired)
     {
         UpdateBatteryConditionCallBack callBack
             = new UpdateBatteryConditionCallBack(UpdateBatteryCondition);
         this.Invoke(callBack, new object[] { batteryCondition });
     }
     else
     {
         SetUpdatedBatteryCondition(batteryCondition);
     }
 }
Beispiel #4
0
        public BatteryCondition GetCurrentBatteryCondition()
        {
            var query            = new ObjectQuery(GetWmiBatterySqlQuery);
            var searcher         = new ManagementObjectSearcher(query);
            var collection       = searcher.Get();
            var batteryCondition = new BatteryCondition();

            foreach (var coll in collection)
            {
                var wmiBattery = (ManagementObject)coll;
                batteryCondition
                .SetPlugType(Convert.ToInt32(wmiBattery[BatteryStatusPropertyName]));
                batteryCondition
                .SetChargeStatus(Convert.ToInt32(wmiBattery[BatteryEstimatedChargeRemainingPropertyName]));
                batteryCondition
                .SetEstimatedRunTime(Convert.ToInt32(wmiBattery[BatteryEstimatedRuntimePropertyName]));
            }
            return(batteryCondition);
        }