简体   繁体   English

如何在C#.net Windows应用程序中获取系统内存?

[英]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.

相关问题 如何在C#.net(2010)Windows窗体应用程序中获取TreeView控件中的所有复选框值? - how to get the All the Checkbox values in TreeView control in C#.net(2010) Windows Forms Application? 如何设置Windows 7的桌面应用程序外观(c#.net) - How to set windows 7 like look of desktop application (c#.net) 如何在C#.net的Windows应用程序根目录中读取文件? - How to read file in windows application root directory in C#.net? C#.net中的Windows Services for Console应用程序 - Windows Services for Console application in C#.net 使用C#.NET的多语言Windows应用程序 - Multilingual windows application using C#.NET 在C#.net Windows应用程序中上传文件 - Upload Files in C#.net Windows Application 如何在c#.net中获取用于窗口应用程序的时区名称? - How to get the timezone Name in c#.net for window application? 如何在c#.net窗口中获取存储过程的所有代码并在c#.net窗口中创建存储过程的textFile - how to get all code of stored procedure in c#.net window and create textFile of storedprocedure in C#.net window Application 如何使ac#.net应用程序可移植 - How to make a c#.net application portable 如何在C#.net应用程序中使用扫描仪 - How to use scanner in c#.net application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM