For the umpteenth time my laptop just shut down in the middle of my game because my power cable had disconnected without me noticing it.
Now I want to write a little C# program that detects when my power cable disconnects and then emits a nice long System beep. What API could I use for that?
Check the AC adapter and cables (including the power cable) for any signs of physical damage or overheating. Check if the pin inside the plug or adapter port is bent, broken, or damaged.
If you've plugged your computer into an outlet, but notice it isn't charging, or if your computer shuts itself down while it's plugged in, you may have a faulty AC adapter. Plug your AC adapter into a different outlet and see if your laptop charges.
This should be trivial to implement using the SystemInformation.PowerStatus property. And even though that lives in Windows.Forms, it should be perfectly usable from a system service.
For a solution that also works on the Compact Framework, see HOWTO: Get the Device Power Status
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With