|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- using Microsoft.Win32;
-
- using System;
- using System.Runtime.InteropServices;
-
- namespace Common.system
- {
- /// <summary>
- /// 释放内存帮助类 创建人:赵耀 创建时间:2020年8月12日
- /// </summary>
- public class FreeMemoryHelper
- {
- [DllImport("kernel32.dll")]
- private static extern bool SetProcessWorkingSetSize(IntPtr proc, int min, int max);
-
- /// <summary>
- /// Close、Hide、最小化页面时调用此方法,释放占用内存并重新分配 将暂时不需要的内容放进虚拟内存,当应用程序重新激活时,会将虚拟内存的内容重新加载到内存。
- /// 不宜过度频繁的调用该方法,频繁调用会降低使使用性能。 创建人:赵耀 创建时间:2020年8月12日
- /// </summary>
- public static void ReallocateMemory()
- {
- GC.Collect();
- GC.WaitForPendingFinalizers();
-
- if (Environment.OSVersion.Platform == PlatformID.Win32NT)
- {
- SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
- }
- }
-
- /// <summary>
- /// ---屏蔽DevExpress试用信息 与内存释放无关
- /// </summary>
- public static void SetDate()
- {
- CreateKey();
- RegistryKey currentUser = Registry.CurrentUser;
- RegistryKey registryKey = currentUser.OpenSubKey("SOFTWARE\\DevExpress\\Components", writable: true);
- registryKey.GetValue("LastAboutShowedTime");
- string value = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss");
- registryKey.SetValue("LastAboutShowedTime", value);
- currentUser.Dispose();
- }
-
- // 摘要: 创建键值
- private static void CreateKey()
- {
- RegistryKey currentUser = Registry.CurrentUser;
- if (currentUser.OpenSubKey("SOFTWARE\\DevExpress\\Components", writable: true) == null)
- {
- RegistryKey registryKey = currentUser.CreateSubKey("SOFTWARE\\DevExpress\\Components");
- registryKey.CreateSubKey("LastAboutShowedTime").SetValue("LastAboutShowedTime", DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"));
- registryKey.CreateSubKey("DisableSmartTag").SetValue("LastAboutShowedTime", false);
- registryKey.CreateSubKey("SmartTagWidth").SetValue("LastAboutShowedTime", 350);
- }
-
- currentUser.Dispose();
- }
- }
- }
|