爲什麼下面的代碼引發錯誤Instance 'taskmgr' does not exist in the specified Category.
時,我沒有通過PARAMS在構造函數爲什麼在PerformanceCounter對象上調用NextValue()會拋出錯誤?
var cpuCounter = new PerformanceCounter();
cpuCounter.CategoryName = "Processor";
cpuCounter.CounterName = "% Processor Time";
cpuCounter.InstanceName = "taskmgr";
cpuCounter.NextValue();
但是,當我做同樣通過傳遞PARAMS在構造函數不會引發錯誤。
var cpuCounter = new PerformanceCounter(
"Processor",
"% Processor Time",
"taskmgr");
cpuCounter.NextValue();
更新: 我試着在每一個進程的名稱,不僅是「taskmgr」,結果是一樣的!
什麼問題?
實際上它給了同樣的錯誤了我在這兩種情況下 – ionden 2012-03-05 16:10:59
你確定taskmgr實際上運行時,你執行這兩個代碼塊? – ken2k 2012-03-05 16:13:24
是的。我已經仔細檢查過了。它發生在我把每個進程名稱 – theateist 2012-03-05 16:17:15