1

メモリ パフォーマンス カウンターを使用しようとしています。

System.Diagnostics.PerformanceCounter theMemCounter = 
    new System.Diagnostics.PerformanceCounter("Memory", "Available MBytes",
    System.Diagnostics.Process.GetCurrentProcess().ProcessName, true);

var memStart = theMemCounter.NextValue();

しかし、2 行目で次のエラーが発生します。

Counter is single instance, instance name 'WebDev.WebServer40' is not valid for this counter category.

何が問題ですか?

4

1 に答える 1

2

Ottoni さん、この特定のパフォーマンス カウンターにプロセスを指定することはできないと思います。システム全体で使用可能なメモリを監視するからです。

おそらく、探しているパフォーマンスカウンターは、「.NET CLR Memory(INSTANCE)# Bytes in all Heaps」または .NET CLR Memory カテゴリの他のものであり、すべてまたは指定された .net アプリケーションのメモリ使用量を監視できます。

このカテゴリの詳細については、http: //msdn.microsoft.com/en-us/library/x2tyfybc.aspxをご覧ください。

- 編集

解決:

System.Diagnostics.PerformanceCounter theMemCounter =
    new System.Diagnostics.PerformanceCounter("Process", "Working Set",
    System.Diagnostics.Process.GetCurrentProcess().ProcessName);

var memStart = theMemCounter.NextValue() / 1024 / 1024;
于 2012-04-17T13:26:24.453 に答える