Пример #1
0
    private async Task PreventSleepAsync()
    {
        IPowerSavingInhibitorTask?task = _powerSavingTask;

        if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
        {
            if (task is not null)
            {
                if (!task.Prolong(Timeout))
                {
                    Logger.LogTrace("Failed to prolong the power saving task.");
                    task = null;
                }
            }

            if (task is null)
            {
                Logger.LogTrace("Create new power saving prevention task.");
                _powerSavingTask = await TaskFactory !().ConfigureAwait(false);
            }
        }
        else
        {
            await EnvironmentHelpers.ProlongSystemAwakeAsync().ConfigureAwait(false);
        }
    }
Пример #2
0
 protected override async Task ActionAsync(CancellationToken cancel)
 {
     if (WalletManager.AnyCoinJoinInProgress())
     {
         await EnvironmentHelpers.ProlongSystemAwakeAsync().ConfigureAwait(false);
     }
 }
        protected override async Task ActionAsync(CancellationToken cancel)
        {
            IPowerSavingInhibitorTask?task = _powerSavingTask;

            switch (CoinJoinManager.HighestCoinJoinClientState)
            {
            case CoinJoinClientState.Idle:
                if (task is not null)
                {
                    Logger.LogWarning("Computer idle state is allowed again.");
                    await task.StopAsync().ConfigureAwait(false);

                    _powerSavingTask = null;
                }

                break;

            case CoinJoinClientState.InProgress or CoinJoinClientState.InCriticalPhase:
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    if (task is not null)
                    {
                        if (!task.Prolong(Timeout.Add(TimeSpan.FromMinutes(1))))
                        {
                            Logger.LogTrace("Failed to prolong the power saving task.");
                            task = null;
                        }
                    }

                    if (task is null)
                    {
                        Logger.LogTrace("Create new power saving prevention task.");
                        _powerSavingTask = await TaskFactory !().ConfigureAwait(false);
                    }
                }
                else
                {
                    await EnvironmentHelpers.ProlongSystemAwakeAsync().ConfigureAwait(false);
                }

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Пример #4
0
 public async Task ProlongSystemAwakeCanBeExecutedAsync()
 {
     await EnvironmentHelpers.ProlongSystemAwakeAsync();
 }