2016-09-01 3 views
0

그래서 RAM, 네트워크, 프로세서 등을 사용하는 콘솔에서 인쇄하는 프로그램을 작성했습니다. 그러나 사용 가능한 RAM (메가 비트)은 30 개만 사용하면 0을 보여줍니다 내 16GB 램 중 %.내 프로그램은 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

Nailed it. 그리고 그것이 CPU로드와 같이 보이는 것이 아닌 0으로 인쇄하는 이유는 카운터를 두 번 연속적으로 호출하기 때문일 수 있습니다. –

+0

고마워, 이봐, 바보 같은 ...! –

관련 문제