zoukankan      html  css  js  c++  java
  • .Net Client, WinForm or WPF内存使用控制的代码

      class MemoryClearService
        {
            private static System.Threading.Timer timer;
            public void Start()
            {
                timer = new Timer(Callback, null, TimeSpan.FromSeconds(60), TimeSpan.FromSeconds(30));
            }

            static void Callback(object state)
            {
                MemoryUtil.FlushMemory();
            }
        }

        /// <summary>
        /// ref: http://blog.csdn.net/jingang123gz/archive/2008/07/16/2662975.aspx
        /// </summary>
        class MemoryUtil
        {
            [DllImport("kernel32.dll")]
            public static extern bool SetProcessWorkingSetSize(IntPtr proc, int min, int max);

            public static void FlushMemory()
            {
                GC.Collect();
                GC.WaitForPendingFinalizers();
                if (Environment.OSVersion.Platform == PlatformID.Win32NT)
                {
                    SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
                }
            }
        }
  • 相关阅读:
    Vue-CLI项目-axios模块前后端交互(类似ajax提交)
    Vue-CLI项目中路由传参
    HTML标签嵌套规则
    POJ1050 To the Max
    POJ2488 A Knight's Journey
    POJ1083 Moving Tables
    洛谷P1265 公路修建
    POJ2236 Wireless Network
    洛谷P1991 无线通讯网
    POJ1018 Communication System
  • 原文地址:https://www.cnblogs.com/jianyi0115/p/1749728.html
Copyright © 2011-2022 走看看