C# 我的程序说我还有0Mb内存

C# 我的程序说我还有0Mb内存,c#,performance,C#,Performance,所以我编写了一个程序,在控制台中打印我使用了多少ram、网络、处理器等。但当我只使用我16gb内存的30%时,可用ram(Mb)显示为0 我的代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Diagnostics; using System.Threading; namespa

所以我编写了一个程序,在控制台中打印我使用了多少ram、网络、处理器等。但当我只使用我16gb内存的30%时,可用ram(Mb)显示为0

我的代码:

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);
            }

        }
    }
}
这就是它的表现:


您有一个复制/粘贴错误,使用
perfCpuCount
两次:

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

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

您有一个复制/粘贴错误,使用
perfCpuCount
两次:

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

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

你不想打印
perfmodowcount.nextValue()
?你不想打印
perfmodowcount.nextValue()
?搞定了。它之所以打印为0,而不是看起来像CPU负载的东西,可能是因为连续两次快速调用计数器。它打印为0的原因,而不是看起来像CPU负载的东西,可能是因为连续两次快速调用计数器。