币安量化交易
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
782 B

3 years ago
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace Binance.TradeRobot.Common.Helpers
{
/// <summary>
/// 清理内存
/// </summary>
public class ClearMemoryHelper
{
[DllImport("psapi.dll")]
static extern int EmptyWorkingSet(IntPtr hwProc);
public static void ClearMemory(string processName)
{
Process[] processes = string.IsNullOrEmpty(processName) ?
new Process[] { Process.GetCurrentProcess() } :
Process.GetProcessesByName(processName);
try
{
Array.ForEach(processes, p => EmptyWorkingSet(p.Handle));
}
catch { throw; }
}
}
}