我有這段代碼: 我在哪裏創建我的Performance Counter。它執行正常,如果不存在,它也會創建性能計數器,但是當我使用perfmon時,我找不到這個性能計數器。我的表演櫃檯在哪裏?它被創建,但我無法在perfmon中看到它
發生了什麼事?
const string _categoryName = "MyPerformanceCounter";
if (!PerformanceCounterCategory.Exists(_categoryName))
{
CounterCreationDataCollection counters = new CounterCreationDataCollection();
CounterCreationData ccdWorkingThreads = new CounterCreationData();
ccdWorkingThreads.CounterName = "# working threads";
ccdWorkingThreads.CounterHelp = "Total number of operations executed";
ccdWorkingThreads.CounterType = PerformanceCounterType.NumberOfItems32;
counters.Add(ccdWorkingThreads);
// create new category with the counters above
PerformanceCounterCategory.Create(_categoryName,
"Performance counters of my app",
PerformanceCounterCategoryType.SingleInstance,
counters);
}
過去我遇到的一個與perf計數器有關的問題是,運行的進程必須是管理員,或者具有創建perf計數器的特定權限。這就是爲什麼通常新的性能計數器是在安裝時而不是運行時創建的。我不記得如果你的應用沒有管理權限會發生什麼;它可能只是默默無法創建計數器。雖然我認爲它會拋出一個例外......不過無論如何,如果你還沒有,就試試以管理員身份運行你的應用。 – CodingWithSpike 2012-07-17 18:51:12
此外,如果您在性能監視器運行時創建的計數器,你需要重新啓動性能監視器,使其認識到新的計數器。 – 2012-07-17 18:58:38
另外,計數器不能立即顯示。有時需要幾秒鐘才能看到它們。 – 2012-07-17 18:59:38