防止睡眠模式

时间:2017-01-05 21:27:45

标签: c++ windows

我正在开发一个程序,要求PC始终保持在线状态。 我想允许我的程序在显示器关闭时运行但是阻止睡眠模式。

例如,如果我将自动睡眠设置为在2分钟不活动后启用,我希望此过程开始并且监视器关闭但CPU保持活动状态并允许我的程序使用CPU。

我认为这条线会这样做,但仍然会出现睡眠模式。

 SetThreadExecutionState(ES_SYSTEM_REQUIRED);

我做错了什么?

1 个答案:

答案 0 :(得分:2)

你需要继续调用该函数(那里有一个禁用其设置的计时器)。或者以int[][] severity = new int[ArraySize][2]; // this array stors ID,severity_code respectively for (int i = 0; i < first.length; i++) { System.out.print("\n _______________________________________________\n" + "| |\n" + "| Case Type |\n" + "|_______________________________________________|\n" + " \n" + " _______________________________________________\n" + "| |\n" + "| 1: Enter 1 for Accident Injury | \n" + "| 2: Enter 2 for Fire Injury | \n" + "| 3: Enter 3 for Electricity Sho | \n" + "| 4: Enter 4 for Heart Attack | \n" + "| 5: Enter 5 for Unconscious | \n" + "| 6: Enter 6 for Otherwise | \n" + "|_______________________________________________|\n" + " > Please enter your choice: \n" + " "); severity[i][0] = ID[i]; // storing ID severity[i][1] = input.nextInt(); // storing severity_code } // now you have associated the user's ID with his severity_code // Then sort severity[][] according to the severity_code which is in the severity[i][1] where 0<=i<=ID.length 作为参数调用它。