[英]How to get System Memory in C#.net windows application?
I am doing build checks and installations on network connected systems. 我正在网络连接的系统上进行构建检查和安装。
How to get System Memory in C#.net windows application? 如何在C#.net Windows应用程序中获取系统内存?
Thanks in advance. 提前致谢。
u can get it with the performance counter.. try using following code snippet.. 您可以使用性能计数器来获取它。尝试使用以下代码段。
using System.Diagnostics;
protected PerformanceCounter ramCounter;
ramCounter = new PerformanceCounter("Memory", "Available MBytes");
/*
Call this method every time you need to get
the amount of the available RAM in Mb
*/
public string getAvailableRAM()
{
return ramCounter.NextValue().ToString() +"Mb";
}
and yeah @neil's link is a good resource 是的,@ neil的链接是很好的资源
I think you can use this for Available Memory, the same for others 我认为您可以将其用于可用内存,其他用户也可以使用
PerformanceCounter availableBytes = new PerformanceCounter("Memory","Available Bytes", true);
double numBytes = availableBytes.RawValue / 1024 /1024; // Mb
availableBytes.Close();
Or You can Add Reference Visual Basic & Add Microsoft.VisualBasic.Devices
for this code 或者,您可以为此代码添加参考Visual Basic并添加Microsoft.VisualBasic.Devices
var Available = new ComputerInfo().AvailablePhysicalMemory;
var Total = new ComputerInfo().TotalPhysicalMemory;
调用GlobalMemoryStatus并检查返回的结构。
You can get data from performance counters in C#, one of the many being the used system memory. 您可以从C#中的性能计数器获取数据,其中许多是已使用的系统内存。 Here's an article on how to do so: 这是有关如何执行此操作的文章:
http://msdn.microsoft.com/en-us/library/s155t6ta(v=vs.71).aspx http://msdn.microsoft.com/zh-CN/library/s155t6ta(v=vs.71).aspx
Of course once you've got this working, you can start getting all kinds of other things for your app relatively easily. 当然,一旦完成这项工作,就可以相对轻松地开始为您的应用获取各种其他功能。 For example, if it was actually total available memory you wanted, or disk I/O. 例如,如果它实际上是所需的总可用内存或磁盘I / O。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.