取单个进程的cpu使用率,要代码能调试。本人做过不过取的不准确求准确的做法 取单个进程的cpu使用率,要代码能调试。本人做过不过取的不准确求准确的做法 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 .NET中有一个System.Diagnostics包,其中的PerformanceCounter和PerformanceCounterCategory可以帮助遍历性能信息。PerformanceCounterCateogory.GetCategories() 返回一个PerformanceCounterCategory数组,其中CategoryName为”Processor“的 PerformanceCounterCategory,包含了CPU占用率的信息。PerformanceCounterCategory category = new PerformanceCounterCategory("Processor");string[] instances = category.GetInstanceNames();一段代码中,如果是双CPU电脑,会返回{"_Total", "0", "1"}三个数组。其中”_Total"永远是总的占用率,而其他数字代表CPU内核。 谢谢csrwgs,不过不是cpu总使用率,而是单个进程的。 csrwgs 我再看下。我有个这个解法的demo原来没考虑双核。如果我试验成功的话会把分加上 Timer tmT; int iTotal, iUser; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { tmT = new Timer(); tmT.Tick += new EventHandler(tmT_Tick); tmT.Interval = 1000; tmT.Start(); } void tmT_Tick(object sender, EventArgs e) { int I = System.Diagnostics.Process.GetCurrentProcess().TotalProcessorTime.Milliseconds; System.Console.WriteLine("{0:P}", (I - iTotal) / 1000.0); iTotal = I; I = System.Diagnostics.Process.GetCurrentProcess().UserProcessorTime.Milliseconds; System.Console.WriteLine("{0:P}", (I - iUser) / 1000.0); iUser = I; } 谁用.Net的C/S结构做过电子拣货系统 怎样用程序写LED灯开启/熄灭/闪烁的程序 急 datagridview 自适应打印 有关tabcontrol控件的问题 关于C# ini文件问题 代码封装小问题 datalist中的子控件的数据挷定 如何将一带格式的字符串写入word,新手求解! try ------------------.net试题---------------------- 如何重绘toolbar底色? var expr = (from d in ctx.VOD_Account .... windows服务启动立刻停止!!!!
string[] instances = category.GetInstanceNames();一段代码中,如果是双CPU电脑,会返回{"_Total", "0", "1"}三个数组。其中”_Total"永远是总的占用率,而其他数字代表CPU内核。
int iTotal, iUser; public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
tmT = new Timer();
tmT.Tick += new EventHandler(tmT_Tick);
tmT.Interval = 1000;
tmT.Start();
} void tmT_Tick(object sender, EventArgs e)
{
int I = System.Diagnostics.Process.GetCurrentProcess().TotalProcessorTime.Milliseconds;
System.Console.WriteLine("{0:P}",
(I - iTotal) / 1000.0);
iTotal = I;
I = System.Diagnostics.Process.GetCurrentProcess().UserProcessorTime.Milliseconds;
System.Console.WriteLine("{0:P}",
(I - iUser) / 1000.0);
iUser = I;
}