是否可以在Windows中以编程方式(以任何语言)知道运行/空闲进程的CPU使用情况?
如果您不在意支持旧的Windows版本(早于Windows XP SP1),则可以使用GetSystemTimes Win32 API函数 。
否则,你必须使用性能计数器 。
在C#您可以执行以下操作:
private PerformanceCounter cpuCounter = new PerformanceCounter("Process", "% Processor Time", Process.GetCurrentProcess().ProcessName); cpuCounter.NextValue(); // it will give you cpu usage
你应该参考这里的细节。