Skip to content

Instantly share code, notes, and snippets.

@aont
Created November 6, 2010 12:17
Show Gist options
  • Save aont/665370 to your computer and use it in GitHub Desktop.
Save aont/665370 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Threading;
using System.Runtime.InteropServices;
namespace StandbyResetter
{
class Program
{
static void Main(string[] args)
{
var cpu_user = new PerformanceCounter("Processor", "% User Time", "_Total");
float cpu;
do
{
cpu = cpu_user.NextValue();
Console.WriteLine("CPU:{0}", cpu);
if (cpu > 20)
SetThreadExecutionState(ExecutionState.SystemRequired);
Thread.Sleep(1000);
} while (true);
}
[DllImport("kernel32.dll")]
extern static ExecutionState SetThreadExecutionState(ExecutionState esFlags);
}
[FlagsAttribute]
public enum ExecutionState : uint
{
// 関数が失敗した時の戻り値
Null = 0,
// スタンバイを抑止
SystemRequired = 1,
// 画面OFFを抑止
DisplayRequired = 2,
// 効果を永続させる。ほかオプションと併用する。
Continuous = 0x80000000,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment