星火微课系统客户端
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

FreeMemoryHelper.cs 2.6KB

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