记录skype的CPU 占用率
var processorCounter = new PerformanceCounter { CategoryName = "Process", CounterName = "% Processor Time", InstanceName = “skype”, MachineName = "." }; processorCounter.NextValue()
记录skype的内存占用
var memoryCounter = new PerformanceCounter { CategoryName = "Process", CounterName = "Working Set - Private", InstanceName = “skype”, MachineName = "." }; memoryCounter.RawValue 返回的是字节为计量单位
获取当前计算计算机的cpu和内存占用情况
counter = new PerformanceCounter("Processor", "% Processor Time", “_total”); counter.NextValue() cpu占用 ComputerInfo ComputerInfo = new ComputerInfo(); ComputerInfo.TotalPhysicalMemory - ComputerInfo.AvailablePhysicalMemory 内存占用
注意, 使用Counter的时候,如果instanceName 不存在, 会出现异常。