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
770 B
28 lines
770 B
4 years ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Text;
|
||
|
using System.Runtime.InteropServices;
|
||
|
|
||
|
namespace AutoFileCopyNet
|
||
|
{
|
||
|
public class MemoryHandler
|
||
|
{
|
||
|
[DllImport("kernel32.dll")]
|
||
|
public static extern bool SetProcessWorkingSetSize(IntPtr handle, int minimumWorkingSetSize, int maximumWorkingSetSize);
|
||
|
|
||
|
/// <summary>
|
||
|
/// 释放内存
|
||
|
/// </summary>
|
||
|
public static void FlushMemory()
|
||
|
{
|
||
|
GC.Collect();
|
||
|
GC.WaitForPendingFinalizers();
|
||
|
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
|
||
|
{
|
||
|
SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|