using Api.Framework.SDK; using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Threading.Tasks; namespace Api.Framework.Timers { /// /// 清理垃圾线程 /// public class ClearGarbageTimer : TimerTask { [DllImport("psapi.dll")] private static extern int EmptyWorkingSet(IntPtr hwProc); public override void Run(object time, bool timeout) { try { //Win32清理内存 Process currentProcess = Process.GetCurrentProcess(); EmptyWorkingSet(currentProcess.Handle); //强制清理GC回收站 GC.Collect(); } catch (Exception ) {} } } }