我正在使用
Windows 8.1,Visual Studio 2013,我有一个运行超过15分钟的C项目.但问题是当我还在调试时窗口进入睡眠状态.
我知道这是因为在运行程序(调试)时超出了睡眠等待时间,我可以通过增加睡眠等待时间或在Windows控制面板电源设置中将设置设置为“从不”来轻松停止.
在程序入口点更改设置,在调试会话结束时恢复设置.
以这个例子为例….
#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); //... }