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);
                }
            }
        }
  • 相关阅读:
    第一章epoll
    sk_buff结构--转载
    邻居子系统1.5 neigh output
    netfilter内核态与用户态 通信 之 sockopt
    邻居子系统1.4
    邻居子系统 1.3
    邻居子系统 1.2
    邻居子系统 1.1
    linux 内核 tasklets 原理以及工作队列
    linux 内核 同步原理
  • 原文地址:https://www.cnblogs.com/jianyi0115/p/1749728.html
Copyright © 2011-2022 走看看