微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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);

   //...
}

原文地址:https://www.jb51.cc/windows/363327.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐