A lightweight .NET library that prevents Windows sleep, display power-off and hibernation during long-running tasks such as streaming, monitoring or automation.
✔ 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
Many users try to prevent Windows sleep using manual power settings or simple utilities.
StreamGuard provides a more reliable solution.
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
Many tools only call SetThreadExecutionState.
StreamGuard also manages:
- display timeout policy
- sleep timeout policy
- optional hibernation control
StreamGuard is implemented as a reusable .NET library that can be integrated into:
- Console applications
- WPF applications
- monitoring tools
- background services
- automation systems
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();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
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;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.
StreamGuard
├─ StreamGuard.Core
├─ StreamGuard.Console
├─ StreamGuard.Wpf
StreamGuard.Core contains the reusable library.
The Console and WPF projects are simple demo hosts.
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.
MIT License