zoukankan      html  css  js  c++  java
  • 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);
                }
            }
        }
    }
  • 相关阅读:
    Java日志第8天 2020.7.13
    Java日志第7天 2020.7.12
    Java日志第6天 2020.7.11
    Java日志第5天 2020.7.10
    Java日志第4天 2020.7.9
    Java日志第3天 2020.7.8
    设计模式_23种设计模式_目录
    ICacheEntry中SlidingExpiration与AbsoluteExpirationRelativeToNow的区别
    MySql中的replace into
    结巴分词
  • 原文地址:https://www.cnblogs.com/equation/p/5481380.html
Copyright © 2011-2022 走看看