我需要检测系统电源状态模式.确切地说,我需要一个事件,当Windows 7从睡眠中醒来时会激活.我已经在使用:
SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
Run Code Online (Sandbox Code Playgroud)
但是这个事件的问题在于它被提升了四次:可能是在计算机进入睡眠模式和计算机唤醒之后.我想要一个只在计算机唤醒时引发的事件.这有什么事吗?
我有一个在Linux上运行的Qt应用程序.
用户可以使用此应用程序将系统切换到mem sleep.
切换到mem睡眠是微不足道的,但是在用户空间中捕获唤醒事件则不然.
我目前的解决方案是使用无限循环来捕获mem睡眠,这样当系统唤醒时,我的应用程序总是从可预测的点继续.
这是我的代码:
void MainWindow::memSleep()
{
int fd;
fd = ::open("/sys/power/state", O_RDWR);// see update 1)
QTime start=QTime::currentTime();
write(fd,"mem",3); // command that triggers mem sleep
while(1){
usleep(5000); // delay 5ms
const QTime &end=QTime::currentTime();// check system clock
if(start.msecsTo(end)>5*2){// if time gap is more than 10ms
break; // it means this thread was frozen for more
} // than 5ms, indicating a wake up after a sleep
start=end;
}
:: close(fd); // the end of this function marks a wake …Run Code Online (Sandbox Code Playgroud)