简体   繁体   English

SetSuspendState()API在Win8中永远不会返回

[英]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. 在我的VC ++项目中,我想插入一个逻辑以编程方式将系统(Windows 8)发送到睡眠状态并恢复。

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. 在这里,我想在SetSuspendState()API调用后从睡眠状态恢复。 But I see the SetSuspendState() call is not at all returning. 但是我看到SetSuspendState()调用根本没有返回。 The control would be struck at the this SetSuspendState() call itself & doesn't return back . 该控件将在此SetSuspendState()调用本身处触击,并且不会返回

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. 但是,如果我强制使系统重新通电,则会看到它又回来了,但是函数“ SetSuspendState()”不会在我的代码中返回。

Can anyone please help me to figure out why is the SetSuspendState() not returning back & how to fix this problem. 任何人都可以帮助我找出SetSuspendState()为什么不返回以及如何解决此问题的原因。 Thanks in advance. 提前致谢。

PS: I'm using VS remote debugger mechanism to achieve this sleep state. PS:我正在使用VS远程调试器机制来实现此睡眠状态。

I imagine that the call to SetSuspendState results in the remote debug server being shutdown. 我想象对SetSuspendState的调用会导致远程调试服务器关闭。 When you call SetSuspendState the system starts a shutdown, and that involves notifying all applications that the system is going down. 当您调用SetSuspendState ,系统开始关闭,这涉及通知所有应用程序系统正在关闭。 When that happens, those applications are expected to terminate. 发生这种情况时,这些应用程序将终止。 So you can expect to lose your connection to the remote debugger. 因此,您可能会失去与远程调试器的连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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