old_flsystem/类库/Api.Framework/Timers/ClearGarbageTimer.cs

39 lines
915 B
C#

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
{
/// <summary>
/// 清理垃圾线程
/// </summary>
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 )
{}
}
}
}