[Rejected] Fix for Scheduler never releases ES_SYSTEM_REQUIRED (1 Viewer)

michael_t

Portal Pro
November 30, 2008
1,258
813
Home Country
Germany Germany
Recently there were some changes in TvService/Scheduler/Scheduler.cs that result in setting ES_SYSTEM_REQUIRED while recording is active but never releasing it after recording is finished. So the system idle timer gets disabled while recording but never gets (re-)enabled, which prevents the system from going to sleep automatically (without user intervention or forced standby by PowerScheduler).
I am quite sure that the real cause for mantis 2693 ("PowerScheduler does not prevent windows standby even when StandbyHandlers disallow it") ist the use of (unpredictable) timer threads calling SetThreadExecutionState() both in Scheduler and in PowerScheduler (see here). This bug has been fixed for Scheduler by gibman_dk ("proper thread used instead of timer"). Thus there is no need for touching the SetThreadExecutionState calls and my proposal is simply to restore these as they were in RC1 and before (see patch).

Michael

PS: gibman_dk's fix should be applied to PowerScheduler too, because it also uses timer threads calling SetThreadExecutionState() to allow and prevent standby. I am just making a complete rework of PowerScheduler that also addresses this issue...
 

Attachments

  • Patch for scheduler never releases ES_SYSTEM_REQUIRED.patch
    30.8 KB

arion_p

Retired Team Member
  • Premium Supporter
  • February 7, 2007
    3,373
    1,626
    Athens
    Home Country
    Greece Greece
    Have you actually witnessed the behavior you are describing?

    The new code uses ES_SYSTEM_REQUIRED but does not specify ES_CONTINUOUS, so it does NOT need to call SetThreadExecutionState() to clear the ES_SYSTEM_REQUIRED flag. In essence it simply periodically resets Windows' idle timer (just like moving the mouse) as long as there is an active recording. As soon as there is no active recording, the idle timer will no longer be reset and after the timer elapses, Windows will put the system to sleep.
     

    michael_t

    Portal Pro
    November 30, 2008
    1,258
    813
    Home Country
    Germany Germany
    Hi arion_p,

    after some research I have to admit that I was completely wrong with my ideas about SetThreadExecutionState beeing called without ES_CONTINUOUS. The way it is used in Scheduler is absolutely ok and cannot block sleep mode, not even if called by various threads...
    So I am sorry for my half-cooked "bug fix" proposal and of course want to withdraw it.:sorry:

    Michael
     

    Users who are viewing this thread

    Top Bottom