using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _20230724_MBJC_upperpc.Common { public static class tools { #region 内存清理 /// ///设置线程工作的空间 /// /// 线程 /// 最小空间 /// 最大空间 /// [System.Runtime.InteropServices.DllImportAttribute("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize", ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Ansi, SetLastError = true)] private static extern int SetProcessWorkingSetSize(IntPtr process, int minimumWorkingSetSize, int maximumWorkingSetSize); public static void ClearMemory(object o) { GC.Collect(); GC.SuppressFinalize(o); if (Environment.OSVersion.Platform == PlatformID.Win32NT) { SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1); } } #endregion } }