我只想使用C#
在我的Windows应用程序表单上显示此过程的值我尝试使用PerformanCounter课程,但我无法弄明白。
var perfCounter = new PerformanceCounter("Network Interface", "Bytes Received/sec", "chrome");
// Initialize to start capturing
perfCounter.NextValue();
for (int i = 0; i < 20; i++)
{
// give some time to accumulate data
Thread.Sleep(1000);
float receive = perfCounter.NextValue() / Environment.ProcessorCount;
Console.WriteLine("Bytes Receive/sec: " + receive);
}
答案 0 :(得分:0)
string pn = "MyProcessName.exe";
var readOpSec = new PerformanceCounter("Process","IO Read Operations/sec", pn);
var writeOpSec = new PerformanceCounter("Process","IO Write Operations/sec", pn);
var dataOpSec = new PerformanceCounter("Process","IO Data Operations/sec", pn);
var readBytesSec = new PerformanceCounter("Process","IO Read Bytes/sec", pn);
var writeByteSec = new PerformanceCounter("Process","IO Write Bytes/sec", pn);
var dataBytesSec = new PerformanceCounter("Process","IO Data Bytes/sec", pn);
var counters = new List<PerformanceCounter>
{
readOpSec,
writeOpSec,
dataOpSec,
readBytesSec,
writeByteSec,
dataBytesSec
};
// get current value
foreach (PerformanceCounter counter in counters)
{
float rawValue = counter.NextValue();
// display the value
}