- C# code
-
public partial class Form1 : Form { System.Windows.Forms.Timer timer = new Timer(); public Form1() { InitializeComponent(); timer.Interval = 30 * 1000; timer.Tick += delegate { SetThreadExecutionState(3); }; //<--- timer.Start(); } [DllImport("kernel32")] extern static int SetThreadExecutionState(int esFlags); }
注意它是在一个定时器中,每隔一阵子进行调用。SetThreadExecutionState的具体解释见
http://msdn.microsoft.com/en-us/library/aa373208(VS.85).aspx