PowerStatus 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package PowerStatus --version 1.0.2                
NuGet\Install-Package PowerStatus -Version 1.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PowerStatus" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PowerStatus --version 1.0.2                
#r "nuget: PowerStatus, 1.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install PowerStatus as a Cake Addin
#addin nuget:?package=PowerStatus&version=1.0.2

// Install PowerStatus as a Cake Tool
#tool nuget:?package=PowerStatus&version=1.0.2                

PowerStatus

Build and test Nuget

C# wrapper for win32's System Power Status

Examples

Get a snapshot of the current power status

var statusProvider = new PowerStatusProvider();
var status = statusProvider.GetStatus();
Console.WriteLine($"{status}");
PowerStatus { AcLineStatus = Offline, BatteryFlags = 0, BatteryLifeProportion = 0.47, BatterySaver = False, BatteryTime = 01:53:54, FullTime =  }

Receive notifications when something changes

var statusProvider = new PowerStatusProvider();
using (statusProvider.Subscribe(
    e => Console.WriteLine(e.ToString()),
    PowerStatusNotification.BatteryProportionChanged(proportion =>
        Console.WriteLine($"The battery proportion is {proportion}")),
    PowerStatusNotification.BatterySaverIsOn(isOn =>
        Console.WriteLine($"Battery saver {(isOn ? "is" : "is not")} on")),
    PowerStatusNotification.CurrentMonitorDisplayState(state =>
        Console.WriteLine($"The current monitor's display state is {state}")),
    PowerStatusNotification.LidIsOpen(isOpen =>
        Console.WriteLine($"The lid {(isOpen ? "is" : "is not")} open")),
    PowerStatusNotification.PowerSchemePersonalityChanged(personality =>
        Console.WriteLine($"The power scheme is {personality}")),
    PowerStatusNotification.PowerSource(powerSource =>
        Console.WriteLine($"The power source is {powerSource}")),
    PowerStatusNotification.PrimaryMonitorIsOn(isOn =>
        Console.WriteLine($"The primary monitor {(isOn ? "is" : "is not")} on")),
    PowerStatusNotification.SessionDisplayState(state =>
        Console.WriteLine($"The session display is {state}")),
    PowerStatusNotification.SystemAwayModeChanged(awayMode =>
        Console.WriteLine($"The system is {awayMode} away mode")),
    PowerStatusNotification.SystemIsBusy(() =>
        Console.WriteLine("The system is busy")),
    PowerStatusNotification.UserIsActive(isActive =>
        Console.WriteLine($"The user {(isActive ? "is" : "is not")} active"))
))
{
    Console.WriteLine("Press any key to stop listening to events...");
    Console.ReadKey(true);
}
Press any key to stop listening to events...
The battery proportion is 0.47
Battery saver is not on
The lid is open
The power scheme is Automatic
The power source is DC
The primary monitor is on
The current monitor's display state is On
The system is busy
The user is active
The session display is On
Product Compatible and additional computed target framework versions.
.NET net6.0-windows7.0 is compatible.  net7.0-windows was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0-windows7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.3 774 9/14/2023
1.0.2 149 9/14/2023
1.0.1 147 9/14/2023
1.0.0 139 9/14/2023
0.0.1 148 9/14/2023