1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace OTSIncAReportApp
- {
- public static class MemoryManagementClass
- {
- /// <summary>
- /// 回收内存
- /// </summary>
- public static void FlushMemory()
- {
- //回收内存
- MemoryManagement mm = new MemoryManagement();
- mm.FlushMemory();
- }
- [System.Runtime.InteropServices.DllImport("coredll.dll")]
- [return: System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)]
- public static extern bool DeleteObject(IntPtr hgdiobj);
- public class MemoryManagement
- {
- [System.Runtime.InteropServices.DllImport("kernel32.dll")]
- public static extern bool SetProcessWorkingSetSize(IntPtr proc, int min, int max);
- public void FlushMemory()
- {
- GC.Collect();
- GC.WaitForPendingFinalizers();
- if (Environment.OSVersion.Platform == PlatformID.Win32NT)
- { SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1); }
- }
- }
- }
- }
|