StreamGuard.Core
1.0.1
dotnet add package StreamGuard.Core --version 1.0.1
NuGet\Install-Package StreamGuard.Core -Version 1.0.1
<PackageReference Include="StreamGuard.Core" Version="1.0.1" />
<PackageVersion Include="StreamGuard.Core" Version="1.0.1" />
<PackageReference Include="StreamGuard.Core" />
paket add StreamGuard.Core --version 1.0.1
#r "nuget: StreamGuard.Core, 1.0.1"
#:package StreamGuard.Core@1.0.1
#addin nuget:?package=StreamGuard.Core&version=1.0.1
#tool nuget:?package=StreamGuard.Core&version=1.0.1
StreamGuard
A lightweight .NET library that prevents Windows sleep, display power-off and hibernation during long-running tasks such as streaming, monitoring or automation.
Features
✔ Prevent Windows sleep ✔ Prevent display power-off ✔ Optional hibernation control ✔ Automatic restore of original power settings ✔ Lightweight .NET library ✔ Works with Console, WPF or background services
Why StreamGuard?
Many users try to prevent Windows sleep using manual power settings or simple utilities.
StreamGuard provides a more reliable solution.
Compared to manual power settings
Manual configuration can easily be forgotten or changed by the system.
StreamGuard:
- automatically applies the required power policies
- keeps the system awake while running
- restores the original settings when finished
Compared to simple "keep awake" tools
Many tools only call SetThreadExecutionState.
StreamGuard also manages:
- display timeout policy
- sleep timeout policy
- optional hibernation control
Designed for developers
StreamGuard is implemented as a reusable .NET library that can be integrated into:
- Console applications
- WPF applications
- monitoring tools
- background services
- automation systems
Quick Start
using StreamGuard.Core;
var options = new StreamGuardOptions();
using var service = new StreamGuardService(options);
service.Log += Console.WriteLine;
await service.StartAsync();
// long running work here
await Task.Delay(TimeSpan.FromHours(1));
await service.StopAsync();
Architecture
StreamGuard is built around a small service layer that manages Windows power APIs.
+-----------------------+
| Console / WPF / Host |
+-----------+-----------+
|
v
+-----------------------+
| StreamGuardService |
+-----------+-----------+
|
+-----+-----+
| |
v v
+-----------+ +------------------+
| Options | | Snapshot |
+-----------+ +------------------+
|
v
+-------------------------------+
| Internal Windows integration |
+---------------+---------------+
|
+------+------+
| |
v v
PowerPolicyApi HibernateFacade
| |
v v
powrprof.dll powercfg.exe
Service Lifecycle
Stopped
|
v
Starting
|
v
Capture snapshot
|
v
Apply policy
|
v
Running
|
v
Maintain loop
|
v
Stopping
|
v
Restore snapshot
|
v
Stopped
The service also exposes events:
service.StateChanged += s => Console.WriteLine($"State: {s}");
service.Log += Console.WriteLine;
Configuration
Behavior can be customized using StreamGuardOptions.
Example:
var options = new StreamGuardOptions
{
MaintainInterval = TimeSpan.FromSeconds(30),
PreventDisplayOff = true,
PreventSleep = true,
DisableHibernate = true,
DisplayTimeoutAcSeconds = 0,
DisplayTimeoutDcSeconds = 0,
SleepTimeoutAcSeconds = 0,
SleepTimeoutDcSeconds = 0
};
A value of 0 usually means never.
Project Structure
StreamGuard
├─ StreamGuard.Core
├─ StreamGuard.Console
├─ StreamGuard.Wpf
StreamGuard.Core contains the reusable library.
The Console and WPF projects are simple demo hosts.
Windows Requirements
StreamGuard relies on Windows power APIs.
Recommended environment:
- Windows 10 or Windows 11
- .NET 6 or later
Some power policy operations may require administrator privileges.
License
MIT License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0-windows7.0 is compatible. net10.0-windows was computed. |
-
net9.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.