1

I am doing build checks and installations on network connected systems.

How to get System Memory in C#.net windows application?

Thanks in advance.

Rajesh Kumar
  • 13
  • 2
  • 5

4 Answers4

1

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

Shekhar_Pro
  • 18,056
  • 9
  • 55
  • 79
  • 1
    and in MSDN its mentioned that u need to be a member of the Performance Monitor Users group or have administrative privileges. – Shekhar_Pro Jan 07 '11 at 11:50
0

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

 var Available = new ComputerInfo().AvailablePhysicalMemory;
 var Total = new ComputerInfo().TotalPhysicalMemory;
Trương Long
  • 100
  • 1
  • 11
0

Call GlobalMemoryStatus and examine the returned structure.

user541686
  • 205,094
  • 128
  • 528
  • 886
0

You can get data from performance counters in C#, one of the many being the used system memory. Here's an article on how to do so:

http://msdn.microsoft.com/en-us/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.

Neil Barnwell
  • 41,080
  • 29
  • 148
  • 220