更新:2007 年 11 月
您可以藉由擷取 PerformanceCounter 類別之 RawValue 屬性目前的值,來擷取原始效能計數器值。
若要擷取計數器的原始值
建立 PerformanceCounter 執行個體,並設定為與所需的分類和計數器互動。如需詳細資訊,請參閱 HOW TO:建立 PerformanceCounter 元件執行個體或 HOW TO:設定 PerformanceCounter 元件執行個體。
擷取 RawValue 屬性目前的值。
下列範例會說明如何使用 RawValue 屬性,來擷取 % Processor Time 計數器目前的值:
Dim MyCounter As New PerformanceCounter() MyCounter.CategoryName = "Processor" MyCounter.CounterName = "% Processor Time" MyCounter.InstanceName = "_Total" Dim raw As Int64 raw = MyCounter.RawValueSystem.Diagnostics.PerformanceCounter myCounter = new System.Diagnostics.PerformanceCounter(); myCounter.CategoryName = "Processor"; myCounter.CounterName = "% Processor Time"; myCounter.InstanceName = "_Total"; long raw = myCounter.RawValue;