Click here to Skip to main content
15,902,112 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
what is the namespace to access system charging in c#, or how can i manipulate system charging
Posted
Comments
James Okpe George 24-Jul-13 17:57pm    
What do u mean by system charging???. Do u mean like charging of the batteries?, if that, I don't think there is a namespace for that in c#
Sergey Alexandrovich Kryukov 24-Jul-13 18:38pm    
You should also understand that namespace does not give you access to anything, ever. What can do it is referencing of some assembly.
—SA
[no name] 24-Jul-13 19:55pm    
system charging ?? what do you mean like the charge level ??
Sergey Alexandrovich Kryukov 24-Jul-13 20:18pm    
Maybe a battery charge...
—SA

1 solution

Please check the following links.

This is solution for battery health, found in stack overflow.
http://stackoverflow.com/questions/8945986/find-out-battery-status-in-c-sharp-or-net[^]

Please check win32_Battery Class. I don't know more about it.
You may please refer the MSDN documentation for that,
http://msdn.microsoft.com/en-us/library/windows/desktop/aa394074%28v=vs.85%29.aspx[^]

Please find copied the code, i think it will answer your question.
I tried this code and its working fine for me.

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;
using Microsoft.Win32;

namespace WpfSample
{
    public partial class MainWindow : Window
    {
 
        public MainWindow()
        {
            InitializeComponent();
            SystemEvents.PowerModeChanged += new
                   PowerModeChangedEventHandler(SystemEvents_PowerModeChanged);
        }
 
       void SystemEvents_PowerModeChanged(object sender, 
                                                   PowerModeChangedEventArgs e)
       {
     switch (System.Windows.Forms.SystemInformation.PowerStatus.BatteryChargeStatus)
                {
                case System.Windows.Forms.BatteryChargeStatus.Low:
                        MessageBox.Show("Battery is running low.", "Low Battery");
                       break;
                case System.Windows.Forms.BatteryChargeStatus.Critical:
                       MessageBox.Show("Battery is critcal", "Critical Battery");
                       break;             
                case System.Windows.Forms.BatteryChargeStatus.Charging:
                       MessageBox.Show("Battery is Charging.", "Charging Battery");
                       break;
                case System.Windows.Forms.BatteryChargeStatus.High:
                       MessageBox.Show("Battery is Good.", "High Battery");
                       break;
                case System.Windows.Forms.BatteryChargeStatus.NoSystemBattery:
                       MessageBox.Show("Battery not found.", "Battery Not found");
                       break;
                case System.Windows.Forms.BatteryChargeStatus.Unknown:
                       MessageBox.Show("Battery status unknown.", "Unknown");
                       break;
               }
         }
    }

}
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900