/// <summary>
/// 定时清理内存
/// </summary>
private void FulshMemory()
{
m_timer = new System.Threading.Timer(new TimerCallback(FulshMemory));
m_timer.Change(1000, 10000);
}
private void FulshMemory(object o)
{
ReduceMemory();
}
[DllImport("kernel32.dll")]
public static extern bool SetProcessWorkingSetSize(IntPtr proc, int min, int max);
/// <summary>
/// 清理内存
/// </summary>
public static void ReduceMemory()
{
long MaxSize = 50000000;
System.Diagnostics.Process process = System.Diagnostics.Process.GetCurrentProcess();
if (process.WorkingSet64 >= MaxSize && Environment.OSVersion.Platform == PlatformID.Win32NT)
{
GC.Collect();
GC.WaitForPendingFinalizers();
SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
}
}