Commit d6856b42 LN

增加内存回收代码

1 个父辈 58348cc0
...@@ -11,6 +11,7 @@ using System.Diagnostics; ...@@ -11,6 +11,7 @@ using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
...@@ -459,6 +460,31 @@ namespace OnlineStore.AssemblyLine ...@@ -459,6 +460,31 @@ namespace OnlineStore.AssemblyLine
Clipboard.SetDataObject(logBox.Text); Clipboard.SetDataObject(logBox.Text);
MessageBox.Show("已复制日志到粘贴板!"); MessageBox.Show("已复制日志到粘贴板!");
} }
#region 内存回收
[DllImport("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize")]
public static extern int SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize);
/// <summary>
/// 释放内存
/// </summary>
public static void ClearMemory()
{
try
{
GC.Collect();
GC.WaitForPendingFinalizers();
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
}
}
catch (Exception ex)
{
LogUtil.error("ClearMemory 出错:" + ex.ToString());
}
}
#endregion
private DateTime lastLogTime = DateTime.Now; private DateTime lastLogTime = DateTime.Now;
PerformanceCounter curtime = null; PerformanceCounter curtime = null;
private void LogM() private void LogM()
...@@ -484,6 +510,7 @@ namespace OnlineStore.AssemblyLine ...@@ -484,6 +510,7 @@ namespace OnlineStore.AssemblyLine
LogUtil.info(sbResult.ToString()); LogUtil.info(sbResult.ToString());
} }
} }
ClearMemory();
} }
catch (Exception ex) catch (Exception ex)
{ {
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!