35 lines
1.2 KiB
C#
35 lines
1.2 KiB
C#
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 内存清理
|
|
/// <summary>
|
|
///设置线程工作的空间
|
|
/// </summary>
|
|
/// <param name="process">线程</param>
|
|
/// <param name="minSize">最小空间</param>
|
|
/// <param name="maxSize">最大空间</param>
|
|
/// <returns></returns>
|
|
[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
|
|
}
|
|
}
|