星火微课系统客户端
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

FreeMemoryHelper.cs 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. if (registryKey != null)
  35. {
  36. registryKey.GetValue("LastAboutShowedTime");
  37. string value = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss");
  38. registryKey.SetValue("LastAboutShowedTime", value);
  39. }
  40. currentUser.Dispose();
  41. }
  42. // 摘要: 创建键值
  43. private static void CreateKey()
  44. {
  45. RegistryKey currentUser = Registry.CurrentUser;
  46. if (currentUser.OpenSubKey("SOFTWARE\\DevExpress\\Components", writable: true) == null)
  47. {
  48. RegistryKey registryKey = currentUser.CreateSubKey("SOFTWARE\\DevExpress\\Components");
  49. if (registryKey != null)
  50. {
  51. registryKey.CreateSubKey("LastAboutShowedTime")?.SetValue("LastAboutShowedTime", DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"));
  52. registryKey.CreateSubKey("DisableSmartTag")?.SetValue("LastAboutShowedTime", false);
  53. registryKey.CreateSubKey("SmartTagWidth")?.SetValue("LastAboutShowedTime", 350);
  54. }
  55. }
  56. currentUser.Dispose();
  57. }
  58. }
  59. }