2016-09-01 20 views
0

だから、私はRAM、ネットワーク、プロセッサなどを使用してコンソールを印刷するプログラムを書いていました。私の16GBのRAMの%。私のプログラムは、0MbのRAMが残っていると言っています

マイコード:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Diagnostics; 
using System.Threading; 


namespace Perf_Monitor 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      PerformanceCounter perfCpuCount = new  PerformanceCounter("Processor Information", "% Processor Time", "_Total"); 
      PerformanceCounter perfMemDowCount = new  PerformanceCounter("Memory", "Available MBytes"); 
      PerformanceCounter perfNetDowCount = new  PerformanceCounter("Network Adapter", "Bytes Received/sec", "Intel[R] 82579V  Gigabit Network Connection"); 
      PerformanceCounter perfNetUpCount = new  PerformanceCounter("Network Adapter", "Bytes Sent/sec", "Intel[R] 82579V Gigabit  Network Connection"); 



      while (true) 
      { 
       Thread.Sleep(1000); 
       Console.WriteLine("CPU Load:   {0}%",  perfCpuCount.NextValue()); 
       Console.WriteLine("Available RAM:  {0}",  perfCpuCount.NextValue()); 
       Console.WriteLine("Network Usage Down: {0}Mbit/s",  perfNetDowCount.NextValue()/125000); 
       Console.WriteLine("Network Usage Up: {0}Mbit/s",  perfNetUpCount.NextValue()/125000); 
      } 

     } 
    } 
} 

これは、それが現れる方法です:

My Program

+1

'perfMemDowCount.nextValue()'を印刷しませんか? –

答えて

2

あなたが二回perfCpuCountを使用して、コピー/貼り付けエラーがあります。

Console.WriteLine("CPU Load: {0}%",  perfCpuCount.NextValue()); 
Console.WriteLine("Available RAM: {0}", perfCpuCount.NextValue()); 

べきbe:

Console.WriteLine("CPU Load: {0}%",  perfCpuCount.NextValue()); 
Console.WriteLine("Available RAM: {0}", perfMemDowCount.NextValue()); 
+0

それに釘付け。そして、CPU負荷のようなものではなく、0として印刷する理由は、カウンタへの2回の呼び出しが急速に続くためです。 –

+0

おかげで私の馬鹿... –

関連する問題