2023-04-24, 02:40 AM
I'm not sure why Windows is choosing to go to sleep that quickly. The 'sleep unattended idle timeout' should only start counting from when NextPVR tell Window's it's no longer in use.
|
2023-04-24, 02:40 AM
I'm not sure why Windows is choosing to go to sleep that quickly. The 'sleep unattended idle timeout' should only start counting from when NextPVR tell Window's it's no longer in use.
2023-04-24, 02:50 AM
I would set unattended sleep to zero and just let regular sleep settings control sleep and see what happens in your case.
Martin (2023-04-24, 02:40 AM)sub Wrote: I'm not sure why Windows is choosing to go to sleep that quickly. The 'sleep unattended idle timeout' should only start counting from when NextPVR tell Window's it's no longer in use. If the server is fast enough, streaming one channel isn't demanding enough for Windows to consider it active as mentioned here. It seems logical as you say that while a power request is active, Windows 11 shouldn't consider the system to be idle but it seems the idle timer doesn't take power requests into account in practice. @Martin: I'll try to set 'sleep unattended idle timeout' to zero as you said and see what that does. I didn't even know about this hidden setting until you taught me about it. Currently it's set equal to my hibernate timeout.
2023-04-29, 04:12 AM
(2023-04-24, 02:50 AM)mvallevand Wrote: I would set unattended sleep to zero and just let regular sleep settings control sleep and see what happens in your case.I have now set unattended sleep to zero as you suggested and it didn't make any difference to the sleeping too early issue. (2023-04-24, 02:40 AM)sub Wrote: I'm not sure why Windows is choosing to go to sleep that quickly. The 'sleep unattended idle timeout' should only start counting from when NextPVR tell Window's it's no longer in use.I set "hibernate after" to 5 min for quick testing ("sleep after" is never). Below is a tweaked powershell script gotten online that reads the "hibernate after" setting, creates a power request, waits for that amount of seconds then removes the request and exits. I ran the script twice (the second time adding 3 min to the hibernateSettingSeconds variable) and observed the following. Code: 10:52: started 5 min power request
10:57: windows 11 Pro hibernated
11:02: started 8 min (5 min + 3 min) power request
11:10: windows 11 Pro hibernatedOn my Windows 11 Pro it appears the power request only prevents the machine from hibernating/sleeping while it is present but does not prevent the timer from counting down. If the task were demanding enough (NextPVRServer and this script are not), then the CPU activity would prevent the timer from counting down (not the power request). If I can provide any extra useful information about my server please ask. Code: # ---------------------------------------------------
# Script: C:\Users\stefstr\Documents\GitHub\PowerShell\Examples\SuspendPowerPlan.ps1
# Version: 0.1
# Author: Stefan Stranger
# Date: 07/05/2014 15:01:57
# Description: Helper Function to Suspend Power Plan when running PowerShell scripts
# Comments:
# Disclamer: This Sample Code is provided for the purpose of illustration only and is not intended to be used in a production environment.
# ---------------------------------------------------
<#
.Synopsis
Function to suspend your current Power Plan settings when running a PowerShell script.
.DESCRIPTION
Function to suspend your current Power Plan settings when running a PowerShell script.
Scenario: When downloading files using Robocopy from PowerShell you don't want your
laptop to go into sleep mode.
.EXAMPLE
Suspend-PowerPlan -script c:\scripts\mylongrunningscript.ps1
Run mylongrunningscript with sleep idle timeout prevented
.EXAMPLE
Suspend-Powerplan -script c:\scripts\mylongrunningscript.ps1 -option Display -Verbose
Run mylongrunningscript with Display idle timeout prevented and verbose messages
.LINK
http://www.microsofttranslator.com/bv.aspx?from=ru&to=en&a=http%3A%2F%2Fsocial.technet.microsoft.com%2FForums%2Fen-US%2F1f4754cb-37bf-4e1d-a59f-ec0f1aaf9d1c%2Fsetthreadexecutionstate-powershell%3FThread%3A1f4754cb-37bf-4e1d-a59f-ec0f1aaf9d1c%3DMicrosoft.Forums.Data.Models.Discussion%26ThreadViewModel%3A1f4754cb-37bf-4e1d-a59f-ec0f1aaf9d1c%3DMicrosoft.Forums.CachedViewModels.ThreadPageViewModel%26forum%3Dscrlangru
#>
function Suspend-Powerplan
{
[CmdletBinding()]
[Alias()]
[OutputType([int])]
Param
(
# Param1 help description
[Parameter(Mandatory=$true,
Position=0)]
$script,
[ValidateSet("Away","Display","System")]
[string]$option
)
$code=@'
[DllImport("kernel32.dll", CharSet = CharSet.Auto,SetLastError = true)]
public static extern void SetThreadExecutionState(uint esFlags);
'@
$ste = Add-Type -memberDefinition $code -name System -namespace Win32 -passThru
$ES_CONTINUOUS = [uint32]"0x80000000" #Requests that the other EXECUTION_STATE flags set remain in effect until SetThreadExecutionState is called again with the ES_CONTINUOUS flag set and one of the other EXECUTION_STATE flags cleared.
$ES_AWAYMODE_REQUIRED = [uint32]"0x00000040" #Requests Away Mode to be enabled.
$ES_DISPLAY_REQUIRED = [uint32]"0x00000002" #Requests display availability (display idle timeout is prevented).
$ES_SYSTEM_REQUIRED = [uint32]"0x00000001" #Requests system availability (sleep idle timeout is prevented).
Switch ($option)
{
"Away" {$setting = $ES_AWAYMODE_REQUIRED}
"Display" {$setting = $ES_DISPLAY_REQUIRED}
"System" {$setting = $ES_SYSTEM_REQUIRED}
Default {$setting = $ES_SYSTEM_REQUIRED}
}
Write-Verbose "Power Plan suspended with option: $option"
$ste::SetThreadExecutionState($ES_CONTINUOUS -bor $setting)
#do something
Write-Verbose "Executing $script"
&$script
Write-Verbose "Power Plan suspension ended"
$ste::SetThreadExecutionState($ES_CONTINUOUS)
}
#The original script getting the GUID only worked as admin so use this method instead
$powerScheme = powercfg -getactivescheme
$GUID = $powerScheme.Substring($powerScheme.IndexOf(":")+2)
$GUID = $GUID.Substring(0, $GUID.IndexOf(" "))
#Write-Host "GUID = ""$GUID"""
#Get a list of all video idle options for this plan
$Options = powercfg -query $GUID SUB_VIDEO VIDEOIDLE
$index = 0
#Find index of line that contains Turn off screen Settings
For($i=0; $i -lt $Options.Length; $i++)
{
$line = $Options[$i]
if($line.ToLower() -like "*Turn off display after*")
{
$index = $i
break
}
}
#Get a list of all hibernate idle options for this plan
$Options2 = powercfg -query $GUID SUB_SLEEP HIBERNATEIDLE
$index2 = 0
#Find index of line that contains Hibernate Settings
For($i=0; $i -lt $Options2.Length; $i++)
{
$line = $Options2[$i]
if($line.ToLower() -like "*(Hibernate after)*")
{
$index2 = $i
break
}
}
#AC Setting is 6 lines later
$screenOffSetting = $Options[$index + 6]
#trim off the beginning of the string, leaving only the value
$screenOffSettingTrimmed = $screenOffSetting.Substring($screenOffSetting.IndexOf(":")+2)
$screenOffSetting = [int]$screenOffSettingTrimmed / 60 # convert to minutes
#AC Setting is 6 lines later
$hibernateSetting = $Options2[$index2 + 6]
#trim off the beginning of the string, leaving only the value
$hibernateSettingTrimmed = $hibernateSetting.Substring($hibernateSetting.IndexOf(":")+2)
$hibernateSetting = [int]$hibernateSettingTrimmed / 60 # convert to minutes
Write-Host screenOffSetting = $screenOffSetting
Write-Host hibernateSetting = $hibernateSetting
$hibernateSettingSeconds = [int]$hibernateSettingTrimmed
#$hibernateSettingSeconds = [int]$hibernateSettingTrimmed + 3*60
Write-Host hibernateSettingSeconds = $hibernateSettingSeconds
# __main__
if ($MyInvocation.InvocationName -ne '.') {
Suspend-Powerplan {Start-Sleep -Seconds $hibernateSettingSeconds } -option System -Verbose
}
2023-04-29, 03:15 PM
(This post was last modified: 2023-04-29, 03:30 PM by mvallevand.)
Looking at the script I see a problem since you allow sleep with
$ste::SetThreadExecutionState($ES_CONTINUOUS) and I think you also need to reset the timer https://learn.microsoft.com/en-us/window...dfrom=MSDN $ste::SetThreadExecutionState($ES_CONTINUOUS | $ES_SYSTEM_REQUIRED) Maybe this is the issue with NextPVR too? Both seem to required for Windows 11 https://stackoverflow.com/questions/7243...eep-on-win Martin
2023-04-29, 04:23 PM
(2023-04-29, 03:15 PM)mvallevand Wrote: and I think you also need to reset the timer https://learn.microsoft.com/en-us/window...dfrom=MSDNLooks like you may have figured this out. Nice! I'll try the script with the changed line you gave above on the same Win11 Pro system and observe. Could be an idiosyncrasy of Win11.
2023-04-29, 07:27 PM
Just like the winscp author in the stackoverflow link you gave, I can't get the sleep script to work in Win11 the way it did in Win10. Not only does the timer not reset in Win11 anymore on ES_SYSTEM_REQUIRED calls, there is no longer a grace period and systems can sleep right after the power request is lifted as this comment explains.
It seems NextPVRService on Win11 will need to postpone removing the power request for an appropriate/configurable delay after streaming ends.
2023-04-29, 07:41 PM
Did you do your testing or'ing them together?
Martin
2023-04-29, 08:15 PM
Yes and learned that -bor is binary or in powershell. I tried these three combinations and nothing worked. I tend to forget what I'm testing while I'm testing
so if someone with access to Win11 could try that would be more conclusive.Code: $ste::SetThreadExecutionState($ES_CONTINUOUS -bor $ES_SYSTEM_REQUIRED)Code: $ste::SetThreadExecutionState($ES_CONTINUOUS -bor $ES_SYSTEM_REQUIRED)
$ste::SetThreadExecutionState($ES_CONTINUOUS)Code: $ste::SetThreadExecutionState($ES_SYSTEM_REQUIRED)
$ste::SetThreadExecutionState($ES_CONTINUOUS)That stackoverflow Q&A seems to show Win11 is by design much more aggressive at going to sleep than Win10.
2023-04-30, 12:57 AM
(This post was last modified: 2023-04-30, 01:03 AM by mvallevand.)
I did some tests with netcore and saw something similar However what if you add -bor $ES_DISPLAY_REQUIRED to the first call? It doesn't make sense but it worked for me.
Martin |
|
|