如何dispay百分比最多的工作总内存使用在Windows XP和7(.NET2)内存使用率
我曾尝试以下解决方案,而更迭(崩溃或冻结)
http://www.pinvoke.net/default.aspx/kernel32/GlobalMemoryStatusEx.html
,并使用
System.GC.GetTotalMemory(true);
工作样本感谢到达林,
[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
public class MEMORYSTATUSEX
{
public uint dwLength = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(MEMORYSTATUSEX));
public uint dwMemoryLoad;
public ulong ullTotalPhys;
public ulong ullAvailPhys;
public ulong ullTotalPageFile;
public ulong ullAvailPageFile;
public ulong ullTotalVirtual;
public ulong ullAvailVirtual;
public ulong ullAvailExtendedVirtual;
}
[System.Runtime.InteropServices.DllImport("kernel32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
static extern bool GlobalMemoryStatusEx(MEMORYSTATUSEX lpBuffer);
private void timer1_Tick(object sender, EventArgs e)
{
var result = new MEMORYSTATUSEX();
if (GlobalMemoryStatusEx(result))
getpercentage(((double)result.ullTotalPhys - result.ullAvailPhys)/result.ullTotalPhys);
}
static void getpercentage(double ratio)
{
string usage = string.Format("usage {0:0%}", ratio);
Console.WriteLine(usage);
}
为什么没有成功?你得到的输出是什么,你预期的输出是什么?不幸的是,这里没有水晶球:) –
“没有成功”是什么意思? –
解决方案1在Windows 7上工作正常,Windows XP冻结,解决方案2不显示正确的百分比 –