gipasoft

Reduce the working set size off the application to a minimum

Apr 21st, 2013
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. [DllImport("kernel32.dll", EntryPoint="SetProcessWorkingSetSize", ExactSpelling=true, CharSet=CharSet.Ansi, SetLastError=true)]
  2. private static extern int SetProcessWorkingSetSize(IntPtr process, int minimumWorkingSetSize, int maximumWorkingSetSize);
  3.  
  4. /// <summary>
  5. /// Reduce the working set size off the application to a minimum.
  6. /// </summary>
  7. public void ReduceWorkingSet()
  8. {
  9. GC.Collect();
  10. GC.WaitForPendingFinalizers();
  11. try
  12. {
  13. if (Environment.OSVersion.Platform == PlatformID.Win32NT)
  14. {
  15. String name = System.Diagnostics.Process.GetCurrentProcess().ProcessName;
  16. SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
  17. }
  18. }
  19. catch (Exception e)
  20. {
  21. Console.Out.WriteLine(e.Message);
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment