feat(windows): add sleep blocker for long jobs

SleepBlocker requests ES_CONTINUOUS | ES_SYSTEM_REQUIRED (optionally the
display) from a dedicated thread, because the execution state belongs to the
calling thread; disposing from any thread clears it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-02 09:46:40 +00:00
1 parent 598433773e
commit e9cd17624c
2 files changed
+82

No files matched your search

@@ -0,0 +1,27 @@
using Titano.Core.Windows.Power;
using Titano.Testing;
namespace Titano.Core.Windows.Tests.Power;
[WindowsOnly]
public sealed class SleepBlockerTests
{
[Test]
[Timeout(10_000)]
public async Task BlocksUntilDisposedFromAnyThread()
{
var blocker = new SleepBlocker();
Assert.True(blocker.IsActive);
// Disposing on another pool thread must still clear the request made by the owner thread.
await Task.Run(blocker.Dispose);
blocker.Dispose();
}
[Test]
[Timeout(10_000)]
public void DisplayVariantWorks()
{
using var blocker = new SleepBlocker(keepDisplayOn: true);
Assert.True(blocker.IsActive);
}
}