简体   繁体   中英

SetSuspendState() API never returns in Win8

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.

I imagine that the call to SetSuspendState results in the remote debug server being shutdown. When you call SetSuspendState the system starts a shutdown, and that involves notifying all applications that the system is going down. When that happens, those applications are expected to terminate. So you can expect to lose your connection to the remote debugger.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM