0

I have come across a Lenovo IdeaCentre A540-24ICB system with a scheduled task that wakes the computer to start my application and it seems to start but the system goes back to sleep right away. Sometimes it appears to not start (or goes to sleep so fast nothing is logged yet) so I checked the Windows power sleep options to ensure "Allow wake timers" was enabled but it didn't exist! Searching online I found a registry entry to add to have it show up in the power options and then ensured it's was enabled. However, didn't make a difference.

I have to use the mouse/keyboard for the computer to wake long enough to run the application (it will start where it left off). The application has been used for years and waking and running has worked. It already tells the system to not go to sleep through the api call in the main processing thread (which could take a fraction of a second to get to):

SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED);

I thought that API was enough to prevent system from going to sleep? As mentioned, it has worked for years. It's just this new Lenovo system or the Win10 installed with it doesn't seem to honor it? Is there some other API call that needs to be called? or any checks / fix the app should do to ensure the SetThreadExecutionState() will work?

TIA!!

user3161924
  • 1,849
  • 18
  • 33
  • I think you may be missing the [`ES_AWAYMODE_REQUIRED`](https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setthreadexecutionstate#parameters) flag. If it still doesn't work you could also try with the PowerXXXRequest APIs (PowerCreateRequest, [`PowerSetRequest`](https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-powersetrequest), and PowerClearRequest) which can also prevent the computer from going to sleep (see the `RequestType` parameter of `PowerSetRequest`). – Neitsa Dec 04 '20 at 07:02
  • "Allow wake timers" does not seem to affect the use of `SetThreadExecutionState`, even if it is Enabled or Disabled. In my windows 10, `SetThreadExecutionState` can work very well. Did you try to [deleted a scheduled task](https://answers.microsoft.com/en-us/windows/forum/windows_vista-performance/how-do-i-delete-a-scheduled-task/623fbe6e-5de6-477c-97ae-b008c303453a?auth=1) ? – Strive Sun Dec 04 '20 at 09:49
  • I haven't tried deleting the task and recreating it. It's just the weirdest thing I've seen and it occurred on this new lenovo - wakes, starts, goes back to sleep so fast it may be before SetThreadExecutionState gets called? – user3161924 Dec 04 '20 at 21:13
  • Not sure if the task influences the api. At least, `SetThreadExecutionState` works for me. – Strive Sun Dec 07 '20 at 05:53

0 Answers0