Move the method and add keepsystemawake
MODIFY
WalletWasabi.Gui/Helpers/Utils.cs
WalletWasabi.Gui/Helpers/Utils.cs
@@ -26,27 +26,5 @@ namespace WalletWasabi.Gui.Helpers
return false;
}
-
- [FlagsAttribute]
- private enum EXECUTION_STATE : uint
- {
- ES_AWAYMODE_REQUIRED = 0x00000040,
- ES_CONTINUOUS = 0x80000000,
- ES_DISPLAY_REQUIRED = 0x00000002,
- ES_SYSTEM_REQUIRED = 0x00000001
- // Legacy flag, should not be used.
- // ES_USER_PRESENT = 0x00000004
- }
-
- [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
- private static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);
-
- public static void KeepSystemAwake()
- {
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
- {
- SetThreadExecutionState(EXECUTION_STATE.ES_SYSTEM_REQUIRED);
- }
- }
}
}

MODIFY
WalletWasabi.Tests/UnitTests/Clients/PreventSleepTests.cs
WalletWasabi.Tests/UnitTests/Clients/PreventSleepTests.cs
-using Microsoft.VisualBasic.CompilerServices;
-using SharpDX;
-using System;
-using System.Collections.Generic;
-using System.Text;
-using WalletWasabi.Gui.Helpers;
+using WalletWasabi.Helpers;
using Xunit;
-using Utils = WalletWasabi.Gui.Helpers.Utils;
namespace WalletWasabi.Tests.UnitTests.Clients
{
@@ -14,7 +8,7 @@ namespace WalletWasabi.Tests.UnitTests.Clients
[Fact]
public void PreventSleep()
{
- Utils.KeepSystemAwake();
+ EnvironmentHelpers.KeepSystemAwake();
}
}
}

MODIFY
WalletWasabi/CoinJoin/Client/Clients/CoinJoinClient.cs
WalletWasabi/CoinJoin/Client/Clients/CoinJoinClient.cs
@@ -254,6 +254,11 @@ namespace WalletWasabi.CoinJoin.Client.Clients
using (await MixLock.LockAsync().ConfigureAwait(false))
{
+ if (State.AnyCoinsQueued())
+ {
+ EnvironmentHelpers.KeepSystemAwake();
+ }
+
foreach (var ongoingRound in State.GetActivelyMixingRounds())
{
await TryProcessRoundStateAsync(ongoingRound).ConfigureAwait(false);

MODIFY
WalletWasabi/Helpers/EnvironmentHelpers.cs
WalletWasabi/Helpers/EnvironmentHelpers.cs
@@ -14,6 +14,17 @@ namespace WalletWasabi.Helpers
{
public static class EnvironmentHelpers
{
+ [FlagsAttribute]
+ private enum EXECUTION_STATE : uint
+ {
+ ES_AWAYMODE_REQUIRED = 0x00000040,
+ ES_CONTINUOUS = 0x80000000,
+ ES_DISPLAY_REQUIRED = 0x00000002,
+ ES_SYSTEM_REQUIRED = 0x00000001
+ // Legacy flag, should not be used.
+ // ES_USER_PRESENT = 0x00000004
+ }
+
private const int ProcessorCountRefreshIntervalMs = 30000;
private static volatile int InternalProcessorCount;
@@ -249,5 +260,16 @@ namespace WalletWasabi.Helpers
return fullBaseDirectory;
}
+
+ [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
+ private static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);
+
+ public static void KeepSystemAwake()
+ {
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ {
+ SetThreadExecutionState(EXECUTION_STATE.ES_SYSTEM_REQUIRED);
+ }
+ }
}
}

Move the method and add keepsystemawake