Reputation: 13
I am doing build checks and installations on network connected systems.
How to get System Memory in C#.net windows application?
Thanks in advance.
Upvotes: 1
Views: 6487
Reputation: 110
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;
Upvotes: 0
Reputation: 18420
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
Upvotes: 1
Reputation: 42065
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.
Upvotes: 0