C# .NET: How to check if we're running on battery?

后端 未结 6 1888
既然无缘
既然无缘 2020-12-08 00:41

i want to be a good developer citizen, pay my taxes, and disable things if we\'re running over Remote Desktop, or running on battery.

If we\'re running over remote d

6条回答
  •  眼角桃花
    2020-12-08 01:33

    I believe you can check SystemInformation.PowerStatus to see if it's on battery or not.

    Boolean isRunningOnBattery =
          (System.Windows.Forms.SystemInformation.PowerStatus.PowerLineStatus == 
           PowerLineStatus.Offline);
    

    Edit: In addition to the above, there's also a System.Windows.Forms.PowerStatus class. One of its methods is PowerLineStatus, which will equal PowerLineStatus.Online if it's on AC Power.

提交回复
热议问题