Cross-platform .NET wake lock libraries for preventing system sleep and, optionally, display sleep.
Windows
Install:
dotnet add package Capjan.WakeLock.WindowsUse:
using Capjan.WakeLock;
using var wakeLock = new WindowsWakeLockService();
using var handle = wakeLock.Acquire(WakeLockLevel.PreventSleep);macOS
Install:
dotnet add package Capjan.WakeLock.MacOSUse:
using Capjan.WakeLock;
using var wakeLock = new MacOSWakeLockService();
using var handle = wakeLock.Acquire(WakeLockLevel.PreventSleep);Linux
Install:
dotnet add package Capjan.WakeLock.LinuxUse:
using Capjan.WakeLock;
using var wakeLock = new LinuxWakeLockService();
using var handle = wakeLock.Acquire(WakeLockLevel.PreventSleep);Note
- Keep the returned handle alive as long as you want the wake lock active.
- Dispose the handle to release one acquisition.
- Dispose the service to release all active acquisitions.
- Use
WakeLockLevel.PreventSleepAndDisplayif display sleep should be prevented too. - Use
Capjan.WakeLock.Abstractionsif you only want the shared API (IWakeLockService,WakeLockLevel).
.NET Tool
A simple cross-platform dotnet tool that prevents your machine from sleeping until you press a key.
Source: samples/Capjan.WakeLock.Tool
Install:
dotnet tool install --global Capjan.WakeLock.ToolRun:
wakelockAdd --help to see all options.
dotnet build WakeLock.slnx
dotnet pack WakeLock.slnx --configuration Release- All packable projects in this repository (libraries and
Capjan.WakeLock.Tool) must share one identical version. - Versioning is derived from the Git tag via MinVer (
v<semver>tags). - Releases are published from one repository release so all NuGet artifacts stay aligned.
- CI enforces version consistency across all packable projects.
Permissive MIT license (see LICENSE) that allows commercial and open-source use with minimal obligations.