I am not familiar with disabling of PerformanceCounter, but you can P/Invoke GlobalMemoryStatusEx instead.
using System; |
using System.Collections.Generic; |
using System.ComponentModel; |
using System.Runtime.InteropServices; |
using System.Text; |
|
namespace ConsoleApplication1 |
{ |
class Program |
{ |
[DllImport("kernel32.dll", SetLastError = true)] |
[return: MarshalAs(UnmanagedType.Bool)] |
private static extern bool GlobalMemoryStatusEx(ref MEMORYSTATUSEX lpBuffer); |
|
[StructLayout(LayoutKind.Sequential)] |
private struct MEMORYSTATUSEX |
{ |
public uint dwLength; |
public uint dwMemoryLoad; |
public ulong ullTotalPhys; |
public ulong ullAvailPhys; |
public ulong ullTotalPageFile; |
public ulong ullAvailPageFile; |
public ulong ullTotalVirtual; |
public ulong ullAvailVirtual; |
public ulong ullAvailExtendedVirtual; |
} |
|
static void Main(string[] args) |
{ |
MEMORYSTATUSEX status = new MEMORYSTATUSEX(); |
status.dwLength = (uint)Marshal.SizeOf(typeof(MEMORYSTATUSEX)); |
|
if (!GlobalMemoryStatusEx(ref status)) |
throw new Win32Exception(); |
|
Console.WriteLine("Total physical: {0}", status.ullTotalPhys); |
Console.WriteLine("Avail physical: {0}", status.ullAvailPhys); |
Console.WriteLine("Total pages : {0}", status.ullTotalPageFile); |
Console.WriteLine("Avail pages : {0}", status.ullAvailPageFile); |
Console.ReadLine(); |
} |
} |
} |
|