MP Suspends too soon after scheduled wakeup (1 Viewer)

gloomyandy

MP Donator
  • Premium Supporter
  • September 15, 2006
    424
    14
    65
    Home Country
    United Kingdom United Kingdom
    Hi Bavarian,
    I've not had chance to test the latest svn for long yet but looking at the code change I think there may be a problem. The PowerManager.ForbidHibernation call is designed to be called as a pair with PowerManager.AllowHibernation and it has a counter in it such that if it is called more than once it will not call the SetThreadExecutionState a subsequent time (unless the AllowHibernation call has been made a matching number of times). So calling it multiple times from OnTimer may cause problems.

    It seems to me there are a couple of possible solutions. If you think you can track all of the ways in which the system can resume and enter suspend then you could call ForbidHibernation (when the system starts and wakes up) and AllowHibernation (at exit and when it suspends) at each point, however you would have to ensure that they always matched, not sure if this is possible. Alternately you could create a new method in PowerManager like:

    static public void SystemBusy()
    {
    // Let the system know we are busy and so not to hibernate
    SetThreadExecutionState(ExecutionState.SystemRequired);
    }

    Which basically says that the system is in use (note that it does not use the Continuous flag as it is expected to be called reasonably frequently, and doing it this way should not interfere with other calls to SetThreadExecutionState) . The above would then be called from OnTimer.

    Do you know if anything else uses the functions in PowerManager? I couldn't find any other references. If there are none then maybe it would make sense to remove the Allow/Forbid code and simply rely on the above, to indicate the busy state of the system.

    Just a thought

    Andy
     

    gloomyandy

    MP Donator
  • Premium Supporter
  • September 15, 2006
    424
    14
    65
    Home Country
    United Kingdom United Kingdom
    That was quick! Will check it out when the new build is available!

    Thanks

    Andy
     

    gloomyandy

    MP Donator
  • Premium Supporter
  • September 15, 2006
    424
    14
    65
    Home Country
    United Kingdom United Kingdom
    Hi Folks,
    Well I ran a bunch of tests overnight and so far as I can see this one is fixed now! I guess we should wait to see how MC gets on with this build before marking it fixed....

    Thanks

    Andy
     

    surfermc

    Portal Pro
    May 7, 2006
    369
    17
    Dorset
    Home Country
    England England
    :D for waiting for me. I have been testing this todat withvarious different setting and can confirm that I can have now schedule recordings as expected and the PC is not returning to Suspend too early.

    Many thanks for the fix Andy and Bavarian.
    MC
     

    gloomyandy

    MP Donator
  • Premium Supporter
  • September 15, 2006
    424
    14
    65
    Home Country
    United Kingdom United Kingdom
    Thanks for the feedback MC. I've marked this as fixed.

    Bavarian and Roy, many thanks for helping on this....

    Andy
     

    Users who are viewing this thread

    Top Bottom