I am looking for away to get the current amount physical memory used in MB. Something like in the Task Manager

I am current using PerformanceCounter("Memory", "Available MBytes", true); but its also including the page files (I believe) which is not what I want. Also I want the option of getting the used and not the available memory.
The application I am working on, will monitor the physical memory usage, until the desired threshold is reached. Then it will restart a few windows services.
If you curious as to why I am developing such a program. Some of our programs have memory leaks on the servers, and a we have to restart windows services to release the memory, until we sort out all the memory leaks, I am making this application to help keep the server going, and responsive.
Using PerformanceCounter class, you can get PF Usage details:
You can find all the categories information here, Process Object.
ADDED, you can also get Available Memory details using
PerformanceCounter:Using
PerformanceCounter,NextValue()method you can get the available memory value inMB, later you can compare it with the threshold value to stop the desired Windows Services.Reference: A Simple Performance Counter Application