11# StreamGuard
22
3- StreamGuard is a small Windows utility library that helps prevent the system from entering sleep mode, turning off the display, or entering hibernation during long-running tasks such as streaming.
3+ A lightweight .NET library that prevents Windows sleep, display power- off and hibernation during long-running tasks such as streaming, monitoring or automation .
44
5- The project provides a reusable .NET library (` StreamGuard.Core ` ) and optional demo applications (Console and WPF).
5+ ![ .NET] ( https://img.shields.io/badge/.NET-6%2B-blue )
6+ ![ Platform] ( https://img.shields.io/badge/platform-Windows-lightgrey )
7+ ![ License] ( https://img.shields.io/badge/license-MIT-green )
68
79---
810
911# Features
1012
11- StreamGuard can:
13+ ✔ Prevent Windows sleep
14+ ✔ Prevent display power-off
15+ ✔ Optional hibernation control
16+ ✔ Automatic restore of original power settings
17+ ✔ Lightweight .NET library
18+ ✔ Works with Console, WPF or background services
1219
13- * Prevent the display from turning off
14- * Prevent the system from entering sleep mode
15- * Disable hibernation while running
16- * Maintain the keep-awake state using a background watchdog
17- * Restore the original power settings when stopped
20+ ---
1821
19- The library works by combining:
22+ # Why StreamGuard?
2023
21- * ` SetThreadExecutionState ` (real-time keep awake)
22- * Windows Power Policy APIs (` powrprof.dll ` )
23- * ` powercfg.exe ` where required
24+ Many users try to prevent Windows sleep using manual power settings or simple utilities.
2425
25- ---
26+ StreamGuard provides a more reliable solution.
2627
27- # Project Structure
28+ ### Compared to manual power settings
2829
29- ```
30- StreamGuard
31- ├─ StreamGuard.Core # Main reusable library
32- ├─ StreamGuard.Console # Example console host
33- ├─ StreamGuard.Wpf # Example WPF UI
34- ```
30+ Manual configuration can easily be forgotten or changed by the system.
3531
36- ` StreamGuard.Core ` contains the complete implementation and is the only required component.
32+ StreamGuard:
3733
38- ---
34+ * automatically applies the required power policies
35+ * keeps the system awake while running
36+ * restores the original settings when finished
37+
38+ ### Compared to simple "keep awake" tools
39+
40+ Many tools only call ` SetThreadExecutionState ` .
41+
42+ StreamGuard also manages:
43+
44+ * display timeout policy
45+ * sleep timeout policy
46+ * optional hibernation control
3947
40- # Installation
48+ ### Designed for developers
4149
42- Currently the library can be referenced directly from source.
50+ StreamGuard is implemented as a reusable .NET library that can be integrated into:
4351
44- Later it may be distributed as a NuGet package.
52+ * Console applications
53+ * WPF applications
54+ * monitoring tools
55+ * background services
56+ * automation systems
4557
4658---
4759
48- # Basic Usage
60+ # Quick Start
4961
5062``` csharp
5163using StreamGuard .Core ;
@@ -58,17 +70,93 @@ service.Log += Console.WriteLine;
5870
5971await service .StartAsync ();
6072
61- // Long running work here
62- await Task .Delay (TimeSpan .FromHours (2 ));
73+ // long running work here
74+ await Task .Delay (TimeSpan .FromHours (1 ));
6375
6476await service .StopAsync ();
6577```
6678
6779---
6880
81+ # Architecture
82+
83+ StreamGuard is built around a small service layer that manages Windows power APIs.
84+
85+ ```
86+ +-----------------------+
87+ | Console / WPF / Host |
88+ +-----------+-----------+
89+ |
90+ v
91+ +-----------------------+
92+ | StreamGuardService |
93+ +-----------+-----------+
94+ |
95+ +-----+-----+
96+ | |
97+ v v
98+ +-----------+ +------------------+
99+ | Options | | Snapshot |
100+ +-----------+ +------------------+
101+ |
102+ v
103+ +-------------------------------+
104+ | Internal Windows integration |
105+ +---------------+---------------+
106+ |
107+ +------+------+
108+ | |
109+ v v
110+ PowerPolicyApi HibernateFacade
111+ | |
112+ v v
113+ powrprof.dll powercfg.exe
114+ ```
115+
116+ ---
117+
118+ # Service Lifecycle
119+
120+ ```
121+ Stopped
122+ |
123+ v
124+ Starting
125+ |
126+ v
127+ Capture snapshot
128+ |
129+ v
130+ Apply policy
131+ |
132+ v
133+ Running
134+ |
135+ v
136+ Maintain loop
137+ |
138+ v
139+ Stopping
140+ |
141+ v
142+ Restore snapshot
143+ |
144+ v
145+ Stopped
146+ ```
147+
148+ The service also exposes events:
149+
150+ ``` csharp
151+ service .StateChanged += s => Console .WriteLine ($" State: {s }" );
152+ service .Log += Console .WriteLine ;
153+ ```
154+
155+ ---
156+
69157# Configuration
70158
71- ` StreamGuardOptions ` allows control over which policies are enforced .
159+ Behavior can be customized using ` StreamGuardOptions ` .
72160
73161Example:
74162
@@ -89,38 +177,38 @@ var options = new StreamGuardOptions
89177};
90178```
91179
92- ` 0 ` usually means ** never** .
180+ A value of ` 0 ` usually means ** never** .
93181
94182---
95183
96- # Service Lifecycle
97-
98- The service exposes the following states:
184+ # Project Structure
99185
100186```
101- Stopped → Starting → Running → Stopping
102- ↓
103- Faulted
187+ StreamGuard
188+ ├─ StreamGuard.Core
189+ ├─ StreamGuard.Console
190+ ├─ StreamGuard.Wpf
104191```
105192
106- You can subscribe to events:
193+ ` StreamGuard.Core ` contains the reusable library.
107194
108- ``` csharp
109- service .StateChanged += s => Console .WriteLine ($" State: {s }" );
110- service .Log += Console .WriteLine ;
111- ```
195+ The Console and WPF projects are simple demo hosts.
112196
113197---
114198
115199# Windows Requirements
116200
117201StreamGuard relies on Windows power APIs.
118202
119- * Windows 10 / 11 recommended
120- * Some power policy changes may require administrator privileges
203+ Recommended environment:
204+
205+ * Windows 10 or Windows 11
206+ * .NET 6 or later
207+
208+ Some power policy operations may require administrator privileges.
121209
122210---
123211
124212# License
125213
126- MIT (recommended)
214+ MIT License
0 commit comments