|
| 1 | +# StreamGuard |
| 2 | + |
| 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. |
| 4 | + |
| 5 | +The project provides a reusable .NET library (`StreamGuard.Core`) and optional demo applications (Console and WPF). |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +# Features |
| 10 | + |
| 11 | +StreamGuard can: |
| 12 | + |
| 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 |
| 18 | + |
| 19 | +The library works by combining: |
| 20 | + |
| 21 | +* `SetThreadExecutionState` (real-time keep awake) |
| 22 | +* Windows Power Policy APIs (`powrprof.dll`) |
| 23 | +* `powercfg.exe` where required |
| 24 | + |
| 25 | +--- |
| 26 | + |
| 27 | +# Project Structure |
| 28 | + |
| 29 | +``` |
| 30 | +StreamGuard |
| 31 | + ├─ StreamGuard.Core # Main reusable library |
| 32 | + ├─ StreamGuard.Console # Example console host |
| 33 | + ├─ StreamGuard.Wpf # Example WPF UI |
| 34 | +``` |
| 35 | + |
| 36 | +`StreamGuard.Core` contains the complete implementation and is the only required component. |
| 37 | + |
| 38 | +--- |
| 39 | + |
| 40 | +# Installation |
| 41 | + |
| 42 | +Currently the library can be referenced directly from source. |
| 43 | + |
| 44 | +Later it may be distributed as a NuGet package. |
| 45 | + |
| 46 | +--- |
| 47 | + |
| 48 | +# Basic Usage |
| 49 | + |
| 50 | +```csharp |
| 51 | +using StreamGuard.Core; |
| 52 | + |
| 53 | +var options = new StreamGuardOptions(); |
| 54 | + |
| 55 | +using var service = new StreamGuardService(options); |
| 56 | + |
| 57 | +service.Log += Console.WriteLine; |
| 58 | + |
| 59 | +await service.StartAsync(); |
| 60 | + |
| 61 | +// Long running work here |
| 62 | +await Task.Delay(TimeSpan.FromHours(2)); |
| 63 | + |
| 64 | +await service.StopAsync(); |
| 65 | +``` |
| 66 | + |
| 67 | +--- |
| 68 | + |
| 69 | +# Configuration |
| 70 | + |
| 71 | +`StreamGuardOptions` allows control over which policies are enforced. |
| 72 | + |
| 73 | +Example: |
| 74 | + |
| 75 | +```csharp |
| 76 | +var options = new StreamGuardOptions |
| 77 | +{ |
| 78 | + MaintainInterval = TimeSpan.FromSeconds(30), |
| 79 | + |
| 80 | + PreventDisplayOff = true, |
| 81 | + PreventSleep = true, |
| 82 | + DisableHibernate = true, |
| 83 | + |
| 84 | + DisplayTimeoutAcSeconds = 0, |
| 85 | + DisplayTimeoutDcSeconds = 0, |
| 86 | + |
| 87 | + SleepTimeoutAcSeconds = 0, |
| 88 | + SleepTimeoutDcSeconds = 0 |
| 89 | +}; |
| 90 | +``` |
| 91 | + |
| 92 | +`0` usually means **never**. |
| 93 | + |
| 94 | +--- |
| 95 | + |
| 96 | +# Service Lifecycle |
| 97 | + |
| 98 | +The service exposes the following states: |
| 99 | + |
| 100 | +``` |
| 101 | +Stopped → Starting → Running → Stopping |
| 102 | + ↓ |
| 103 | + Faulted |
| 104 | +``` |
| 105 | + |
| 106 | +You can subscribe to events: |
| 107 | + |
| 108 | +```csharp |
| 109 | +service.StateChanged += s => Console.WriteLine($"State: {s}"); |
| 110 | +service.Log += Console.WriteLine; |
| 111 | +``` |
| 112 | + |
| 113 | +--- |
| 114 | + |
| 115 | +# Windows Requirements |
| 116 | + |
| 117 | +StreamGuard relies on Windows power APIs. |
| 118 | + |
| 119 | +* Windows 10 / 11 recommended |
| 120 | +* Some power policy changes may require administrator privileges |
| 121 | + |
| 122 | +--- |
| 123 | + |
| 124 | +# License |
| 125 | + |
| 126 | +MIT (recommended) |
0 commit comments