• C# Form内存回收


    namespace WebBrowserMemoryTest
    {
        public partial class Form1 : Form
        {
            private int _Pages;
    
            public Form1()
            {
                InitializeComponent();
                webBrowser1.Navigate("http://www.google.com");
            }
    
            private void startButton_Click(object sender, EventArgs e)
            {
                _Pages = 0;
                timer1.Start();
            }
    
            private void stopButton_Click(object sender, EventArgs e)
            {
                timer1.Stop();
            }
    
            private void timer1_Tick(object sender, EventArgs e)
            {
                HtmlElement next = webBrowser1.Document.GetElementById("pnnext");
    
                if (_Pages <= 90)
                {
                    if (null != next)
                    {
                        string href = next.GetAttribute("href");
                        webBrowser1.Navigate(href);
                        _Pages++;
                    }
                    else
                    {
                        timer1.Stop();
                        MessageBox.Show("Next button not found");
                    }
                }
                else
                {
                    timer1.Stop();
                    MessageBox.Show("Done");
                }
            }
    
            private void goButton_Click(object sender, EventArgs e)
            {
                webBrowser1.Navigate(textBox1.Text);
            }
    
            private void freeMemButton_Click(object sender, EventArgs e)
            {
                MemoryManagement.FlushMemory();
            }
        }
    
        public class MemoryManagement
        {
            [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);
                }
            }
        }
    }
  • 相关阅读:
    软件RAID 0
    逻辑卷管理lvm
    磁盘配额quota
    合并 CentOS 6.8 的两个ISO镜像
    挂载mount
    非交互式添加分区
    磁盘分区-gdisk用法
    C博客作业01--分支、顺序结构
    C语言--第0次作业
    浅议正则表达式
  • 原文地址:https://www.cnblogs.com/equation/p/5481380.html
Copyright © 2020-2023  润新知