SetSuspendState() API never returns in Win8

梦想的初衷 提交于 2019-12-11 19:20:32

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/18123179/setsuspendstate-api-never-returns-in-win8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!