我正在嘗試使用C#中的性能計數器類監視openoffice的性能信息。我遇到了一個奇怪的問題,儘管我的程序可以監視其他應用程序信息,但它無法使用相同的步驟正確監視開放式辦公室的性能數據。本質上,我創建一個進程並讓性能計數器使用它的文件名從該進程獲取處理器時間。我注意到,OpenOffice在任務管理器下有兩個進程;一個是soffice.bin,另一個是soffice.exe。 bin文件比exe文件佔用更多的內存,所以我試圖在exe文件給我沒有可用的性能數據(性能控制器保持返回值爲0)後監視它。但是,bin文件具有相同的問題 - 無論我對應用程序做什麼,我都無法獲得任何可用的性能數據。如何從C#中的OpenOffice獲取性能信息?
任何人都可以告訴我爲什麼我沒有得到openoffice性能的任何好讀數?我是否使用了錯誤的進程名稱,還是更隱蔽?
// create a process
p = new Process();
p.StartInfo.UseShellExecute = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.FileName = fileName;
p.Start();
// for open office, I found that the BIN file takes up more memory in the task manager
String name = "C:\\Program Files (x86)\\OpenOffice.org 3\\program\\soffice.bin";
// So I make a performance counter to monitor that.
pc = new System.Diagnostics.PerformanceCounter("Process",
"% Processor Time",
name,
true);
嘿!這工作!非常感謝! – Waffles