相关疑难解决方法(0)

你如何获得计算机的RAM总量?

使用C#,我想获得我的计算机拥有的RAM总量.使用PerformanceCounter,我可以通过设置获得可用ram的数量:

counter.CategoryName = "Memory";
counter.Countername = "Available MBytes";
Run Code Online (Sandbox Code Playgroud)

但我似乎无法找到获得总内存量的方法.我该怎么做呢?

更新:

MagicKat:我在搜索时看到了它,但它不起作用 - "你错过了一个装配或参考吗?".我希望将它添加到参考文献中,但我没有在那里看到它.

c# memory performancecounter

78
推荐指数
10
解决办法
12万
查看次数

C#以%为单位获取已用内存

我已经创建了一个性能计数器,它可以检查%的总内存使用量,但问题是它没有给我与任务管理器显示的相同的值.例如:我的程序说34%,但任务经理说40%.

有任何想法吗?

注意
我尝试获取系统的可用RAM,而不是进程使用的RAM.

现行守则

private PerformanceCounter performanceCounterRAM = new PerformanceCounter();

performanceCounterRAM.CounterName = "% Committed Bytes In Use";
performanceCounterRAM.CategoryName = "Memory";

progressBarRAM.Value = (int)(performanceCounterRAM.NextValue());
            labelRAM.Text = "RAM: " + progressBarRAM.Value.ToString(CultureInfo.InvariantCulture) + "%";
Run Code Online (Sandbox Code Playgroud)

编辑
我用计时器每秒刷新进度条和标签.

c# performancecounter

41
推荐指数
3
解决办法
5万
查看次数

检索计算机上的RAM总量

可能重复:
C# - 如何获得计算机的RAM总量?

以下将检索可用的ram数量:

PerformanceCounter ramCounter;
ramCounter = new PerformanceCounter("Memory", "Available MBytes");
Console.WriteLine("Total RAM: " + ramCounter.NextValue().ToString() + " MB\n\n");
Run Code Online (Sandbox Code Playgroud)

当然我们必须使用System.Diagnostics; 类.

performancecounter是否具有检索特定计算机的RAM量的任何功能?我不是在谈论使用或未使用的ram数量.我说的是机器的内存量.

c# performancecounter

10
推荐指数
1
解决办法
3万
查看次数

标签 统计

c# ×3

performancecounter ×3

memory ×1