Windows在运行长C Visual Studio程序时会休眠

我正在使用 Windows 8.1,Visual Studio 2013,我有一个运行超过15分钟的C项目.但问题是当我还在调试时窗口进入睡眠状态.

我知道这是因为在运行程序(调试)时超出了睡眠等待时间,我可以通过增加睡眠等待时间或在Windows控制面板电源设置中将设置设置为“从不”来轻松停止.

但我想要一个基于编程或Visual Studio解决方案.我希望我的计算机不要在程序的执行(调试)中睡觉.

在程序入口点更改设置,在调试会话结束时恢复设置.

以这个例子为例….

#include <cstdlib>
//include windows.h

using namespace std;

void KeepMonitorActive() {
    // Enable away mode and prevent the sleep idle time-out.
    SetThreadExecutionState(ES_CONTINUOUS | ES_SYstem_required | ES_AWAYMODE_required);
}

void RestoreMonitorSettings() {
    // Clear EXECUTION_STATE flags to disable away mode and allow the system to idle to sleep normally.
    SetThreadExecutionState(ES_CONTINUOUS);
}

int main()
{
    //Add these 2 lines at the entry point in your program
    KeepMonitorActive();
    atexit(RestoreMonitorSettings);

   //...
}

相关文章

Windows2012R2备用域控搭建 前置操作 域控主域控的主dns:自...
主域控角色迁移和夺取(转载) 转载自:http://yupeizhi.blo...
Windows2012R2 NTP时间同步 Windows2012R2里没有了internet时...
Windows注册表操作基础代码 Windows下对注册表进行操作使用的...
黑客常用WinAPI函数整理之前的博客写了很多关于Windows编程的...
一个简单的Windows Socket可复用框架说起网络编程,无非是建...