Let me explain my problem statement:
In my VC++ project I want to insert a logic to send my system (Windows 8) to Sleep state programatically & resume back.
I'm doing it like this (Copying the code snippet) ::
int wait = 100;
LARGE_INTEGER WaitTime;
WaitTime.QuadPart = wait;
WaitTime.QuadPart *= -10000000;
HANDLE hTimer = CreateWaitableTimer(NULL, FALSE, NULL);
if(0 == SetWaitableTimer(hTimer, &WaitTime, 0, NULL, NULL, TRUE))
{
res = false;
return res;
}
if(0 == SetSuspendState(FALSE, FALSE, FALSE))
{
res = false;
return res;
}
The system is going to sleep (monitor is getting turned off).
Here, I want to resume back from sleep state after SetSuspendState() API call. But I see the SetSuspendState() call is not at all returning. The control would be struck at the this SetSuspendState() call itself & doesn't return back.
However, if I forcefully bring the system back to power , I see it come back but the function "SetSuspendState()" doesn't return back in my code.
Can anyone please help me to figure out why is the SetSuspendState() not returning back & how to fix this problem. Thanks in advance.
PS: I'm using VS remote debugger mechanism to achieve this sleep state.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…