#region 将当前进程的内存占用尺寸设置到最小
/// <summary>
/// 将当前进程的内存占用尺寸设置到最小
/// </summary>
/// <returns>0为成功,-1为失败</returns>
private static int SetProcessMemoryToMin()
{
return SetProcessMemoryToMin(System.Diagnostics.Process.GetCurrentProcess().Handle);
}
/// <summary>
/// 将内存占用尺寸设置到最小
/// </summary>
/// <param name="SetProcess">需要设置内存使用范围的程序进程句柄,一般为当前进程,如:System.Diagnostics.Process.GetCurrentProcess().Handle</param>
/// <returns>0为成功,-1为失败</returns>
public static int SetProcessMemoryToMin(IntPtr SetProcess)
{
if (Environment.OSVersion.Platform == PlatformID.Win32NT || Environment.OSVersion.Platform == PlatformID.Win32Windows)
{
try
{
return SetProcessWorkingSetSize(SetProcess, -1, -1);
}
catch { }
}
return -1;
}
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
private static extern int SetProcessWorkingSetSize(IntPtr hProcess, int dwMinimumWorkingSetSize, int dwMaximumWorkingSetSize);
#endregion