星火直播PC
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

FreeMemoryHelper.cs 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using Microsoft.Win32;
  2. using System;
  3. using System.Runtime.InteropServices;
  4. namespace Common.system
  5. {
  6. /// <summary>
  7. /// 释放内存帮助类 创建人:赵耀 创建时间:2020年8月12日
  8. /// </summary>
  9. public class FreeMemoryHelper
  10. {
  11. [DllImport("kernel32.dll")]
  12. private static extern bool SetProcessWorkingSetSize(IntPtr proc, int min, int max);
  13. /// <summary>
  14. /// Close、Hide、最小化页面时调用此方法,释放占用内存并重新分配 将暂时不需要的内容放进虚拟内存,当应用程序重新激活时,会将虚拟内存的内容重新加载到内存。
  15. /// 不宜过度频繁的调用该方法,频繁调用会降低使使用性能。 创建人:赵耀 创建时间:2020年8月12日
  16. /// </summary>
  17. public static void ReallocateMemory()
  18. {
  19. GC.Collect();
  20. GC.WaitForPendingFinalizers();
  21. if (Environment.OSVersion.Platform == PlatformID.Win32NT)
  22. {
  23. SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
  24. }
  25. }
  26. /// <summary>
  27. /// ---屏蔽DevExpress试用信息 与内存释放无关
  28. /// </summary>
  29. public static void SetDate()
  30. {
  31. CreateKey();
  32. RegistryKey currentUser = Registry.CurrentUser;
  33. RegistryKey registryKey = currentUser.OpenSubKey("SOFTWARE\\DevExpress\\Components", writable: true);
  34. registryKey.GetValue("LastAboutShowedTime");
  35. string value = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss");
  36. registryKey.SetValue("LastAboutShowedTime", value);
  37. currentUser.Dispose();
  38. }
  39. // 摘要: 创建键值
  40. private static void CreateKey()
  41. {
  42. RegistryKey currentUser = Registry.CurrentUser;
  43. if (currentUser.OpenSubKey("SOFTWARE\\DevExpress\\Components", writable: true) == null)
  44. {
  45. RegistryKey registryKey = currentUser.CreateSubKey("SOFTWARE\\DevExpress\\Components");
  46. registryKey.CreateSubKey("LastAboutShowedTime").SetValue("LastAboutShowedTime", DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"));
  47. registryKey.CreateSubKey("DisableSmartTag").SetValue("LastAboutShowedTime", false);
  48. registryKey.CreateSubKey("SmartTagWidth").SetValue("LastAboutShowedTime", 350);
  49. }
  50. currentUser.Dispose();
  51. }
  52. }
  53. }