これを試して。GC.GetTotalMemory() で持っていたものを含め、あなたが望むと思うものを提供します。テキスト ラベルを独自のものに置き換えるか、任意の方法で使用する必要があります。ただし、P/Invoke を使用する必要があります...
public struct MEMORYSTATUS
{
public UInt32 dwLength;
public UInt32 dwMemoryLoad;
public UInt32 dwTotalPhys;
public UInt32 dwAvailPhys;
public UInt32 dwTotalPageFile;
public UInt32 dwAvailPageFile;
public UInt32 dwTotalVirtual;
public UInt32 dwAvailVirtual;
}
[DllImport("coredll.dll")]
private static extern void GlobalMemoryStatus(out MEMORYSTATUS lpBuffer);
public static void GetGlobalMemoryStatus(out UInt32 dwTotal, out UInt32 dwAvail,
out UInt32 dwProcTotal, out UInt32 dwProcAvail)
{
MEMORYSTATUS status = new MEMORYSTATUS();
output.Length = (UInt32)System.Runtime.InteropServices.Marshal.SizeOf(output);
GlobalMemoryStatus(out status);
dwTotal = status.dwTotalPhys;
dwAvail = status.dwAvailPhys;
dwProcTotal = status.dwTotalVirtual;
dwProcAvail = status.dwAvailVirtual;
}
private void UpdateMemoryDisplay()
{
/*************************************************************************/
bool IsTotalGB = false;
bool IsUsedGB = false;
uint TotalRamMemory;
uint AvailRamMemory;
uint ProcTotalRamMemory;
uint ProcAvailRamMemory;
GetGlobalMemoryStatus(out TotalRamMemory, out AvailRamMemory,
out ProcTotalRamMemory, out ProcAvailRamMemory);
float TotalMB = (float)((float)TotalRamMemory / (1024 * 1024));
float UsedMB = TotalMB - (float)((float)AvailRamMemory / (1024 * 1024));
int RamPercent = (int)((UsedMB / TotalMB) * 100.0);
if (1000 < TotalMB)
{
TotalMB /= 1000;
IsTotalGB = true;
}
if (1000 < UsedMB)
{
UsedMB /= 1000;
IsUsedGB = true;
}
this.RamMemMinLbl.Text = UsedMB.ToString("0.0") + ((false != IsUsedGB) ? "GB" : "MB");
this.RamMemMaxLbl.Text = TotalMB.ToString("0.0") + ((false != IsTotalGB) ? "GB" : "MB");
this.RamMemPercent.Current = RamPercent;
IsUsedGB = false;
TotalMB = (float)((float)ProcTotalRamMemory / (1024 * 1024));
UsedMB = TotalMB - (float)((float)ProcAvailRamMemory / (1024 * 1024));
if (1000 < UsedMB)
{
UsedMB /= 1000;
IsUsedGB = true;
}
this.ProcRamMemMinLbl.Text = UsedMB.ToString("0.0") + ((false != IsUsedGB) ? "GB" : "MB");
IsUsedGB = false;
UsedMB = (float)((float)GC.GetTotalMemory(false) / (1024 * 1024));
if (1000 < UsedMB)
{
UsedMB /= 1000;
IsUsedGB = true;
}
this.GCMemMinLbl.Text = UsedMB.ToString("0.0") + ((false != IsUsedGB) ? "GB" : "MB");
/*************************************************************************/
}